From 6a50d059a594f35d70af30a33a4b395616663f68 Mon Sep 17 00:00:00 2001 From: Kjetil Kjeka Date: Tue, 6 Feb 2024 20:09:55 +0100 Subject: [PATCH] Bootstrap: Add argument for building llvm bitcode linker --- config.example.toml | 4 ++++ src/bootstrap/configure.py | 2 ++ src/bootstrap/defaults/config.compiler.toml | 2 ++ src/bootstrap/defaults/config.dist.toml | 2 ++ src/bootstrap/defaults/config.library.toml | 2 ++ src/bootstrap/defaults/config.tools.toml | 2 ++ src/bootstrap/src/core/build_steps/compile.rs | 10 ++++++++++ src/bootstrap/src/core/config/config.rs | 4 ++++ src/bootstrap/src/utils/change_tracker.rs | 5 +++++ src/ci/docker/host-x86_64/dist-various-2/Dockerfile | 2 +- 10 files changed, 34 insertions(+), 1 deletion(-) diff --git a/config.example.toml b/config.example.toml index 4fbdccba91104..ddcd0ec02e0dd 100644 --- a/config.example.toml +++ b/config.example.toml @@ -679,6 +679,10 @@ # sysroot. #llvm-tools = true +# Indicates whether the `self-contained` llvm-bitcode-linker, will be made available +# in the sysroot +#llvm-bitcode-linker = false + # Whether to deny warnings in crates #deny-warnings = true diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 4257c0f7991a6..9c43160d455f7 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -54,6 +54,7 @@ def v(*args): o("profiler", "build.profiler", "build the profiler runtime") o("full-tools", None, "enable all tools") o("lld", "rust.lld", "build lld") +o("llvm-bitcode-linker", "rust.llvm-bitcode-linker", "build llvm bitcode linker") o("clang", "llvm.clang", "build clang") o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++") o("control-flow-guard", "rust.control-flow-guard", "Enable Control Flow Guard") @@ -366,6 +367,7 @@ def apply_args(known_args, option_checking, config): set('rust.codegen-backends', ['llvm'], config) set('rust.lld', True, config) set('rust.llvm-tools', True, config) + set('rust.llvm-bitcode-linker', True, config) set('build.extended', True, config) elif option.name in ['option-checking', 'verbose-configure']: # this was handled above diff --git a/src/bootstrap/defaults/config.compiler.toml b/src/bootstrap/defaults/config.compiler.toml index e276f12621188..d93c5fd25a150 100644 --- a/src/bootstrap/defaults/config.compiler.toml +++ b/src/bootstrap/defaults/config.compiler.toml @@ -17,6 +17,8 @@ lto = "off" # Forces frame pointers to be used with `-Cforce-frame-pointers`. # This can be helpful for profiling at a small performance cost. frame-pointers = true +# Build the llvm-bitcode-linker as it is required for running nvptx tests +llvm-bitcode-linker = true [llvm] # Having this set to true disrupts compiler development workflows for people who use `llvm.download-ci-llvm = true` diff --git a/src/bootstrap/defaults/config.dist.toml b/src/bootstrap/defaults/config.dist.toml index 44efdf50b965f..f3c6ffc9bd510 100644 --- a/src/bootstrap/defaults/config.dist.toml +++ b/src/bootstrap/defaults/config.dist.toml @@ -16,6 +16,8 @@ download-ci-llvm = false # Make sure they don't get set when installing from source. channel = "nightly" download-rustc = false +# Build the llvm-bitcode-linker as it is required for running nvptx tests +llvm-bitcode-linker = true [dist] # Use better compression when preparing tarballs. diff --git a/src/bootstrap/defaults/config.library.toml b/src/bootstrap/defaults/config.library.toml index 087544397f5ea..4a1a49b727522 100644 --- a/src/bootstrap/defaults/config.library.toml +++ b/src/bootstrap/defaults/config.library.toml @@ -10,6 +10,8 @@ bench-stage = 0 incremental = true # Make the compiler and standard library faster to build, at the expense of a ~20% runtime slowdown. lto = "off" +# Build the llvm-bitcode-linker as it is required for running nvptx tests +llvm-bitcode-linker = true [llvm] # Will download LLVM from CI if available on your platform. diff --git a/src/bootstrap/defaults/config.tools.toml b/src/bootstrap/defaults/config.tools.toml index 6e6c366002792..94c8b724cbf8c 100644 --- a/src/bootstrap/defaults/config.tools.toml +++ b/src/bootstrap/defaults/config.tools.toml @@ -12,6 +12,8 @@ incremental = true # Using these defaults will download the stage2 compiler (see `download-rustc` # setting) and the stage2 toolchain should therefore be used for these defaults. download-rustc = "if-unchanged" +# Build the llvm-bitcode-linker as it is required for running nvptx tests +llvm-bitcode-linker = true [build] # Document with the in-tree rustdoc by default, since `download-rustc` makes it quick to compile. diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 6a2bff5970f36..242fe3c12b998 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1843,6 +1843,16 @@ impl Step for Assemble { } } + if builder.config.llvm_bitcode_linker_enabled { + let src_path = builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker { + compiler: build_compiler, + target: target_compiler.host, + extra_features: vec![], + }); + let tool_exe = exe("llvm-bitcode-linker", target_compiler.host); + builder.copy(&src_path, &libdir_bin.join(&tool_exe)); + } + // Ensure that `libLLVM.so` ends up in the newly build compiler directory, // so that it can be found when the newly built `rustc` is run. dist::maybe_install_llvm_runtime(builder, target_compiler.host, &sysroot); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 683e0a4302f94..ae5169e938390 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -236,6 +236,7 @@ pub struct Config { pub lld_mode: LldMode, pub lld_enabled: bool, pub llvm_tools_enabled: bool, + pub llvm_bitcode_linker_enabled: bool, pub llvm_cflags: Option, pub llvm_cxxflags: Option, @@ -1099,6 +1100,7 @@ define_config! { dist_src: Option = "dist-src", save_toolstates: Option = "save-toolstates", codegen_backends: Option> = "codegen-backends", + llvm_bitcode_linker: Option = "llvm-bitcode-linker", lld: Option = "lld", lld_mode: Option = "use-lld", llvm_tools: Option = "llvm-tools", @@ -1571,6 +1573,7 @@ impl Config { codegen_backends, lld, llvm_tools, + llvm_bitcode_linker, deny_warnings, backtrace_on_ice, verify_llvm_ir, @@ -1650,6 +1653,7 @@ impl Config { } set(&mut config.lld_mode, lld_mode); set(&mut config.lld_enabled, lld); + set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker); if matches!(config.lld_mode, LldMode::SelfContained) && !config.lld_enabled diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index a348fa3584147..85dfe45111fa9 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -146,4 +146,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Info, summary: "a new `target.*.runner` option is available to specify a wrapper executable required to run tests for a target", }, + ChangeInfo { + change_id: 117458, + severity: ChangeSeverity::Info, + summary: "New option `rust.llvm-bitcode-linker` that will build the llvm-bitcode-linker.", + }, ]; diff --git a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile index e90141bb9a961..abd109a6ea3f9 100644 --- a/src/ci/docker/host-x86_64/dist-various-2/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-various-2/Dockerfile @@ -135,7 +135,7 @@ ENV TARGETS=$TARGETS,x86_64-unknown-uefi # Luckily one of the folders is /usr/local/include so symlink /usr/include/x86_64-linux-gnu/asm there RUN ln -s /usr/include/x86_64-linux-gnu/asm /usr/local/include/asm -ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --disable-docs \ +ENV RUST_CONFIGURE_ARGS --enable-extended --enable-lld --enable-llvm-bitcode-linker --disable-docs \ --set target.wasm32-wasi.wasi-root=/wasm32-wasip1 \ --set target.wasm32-wasip1.wasi-root=/wasm32-wasip1 \ --set target.wasm32-wasi-preview1-threads.wasi-root=/wasm32-wasi-preview1-threads \