Skip to content

Commit 4c36376

Browse files
committed
ci(llvm): drop llvm-config from distribution; build + copy it by hand
CI confirmed what issue #364's analysis predicted: when LLVM_BUILD_TOOLS=Off, cmake's `llvm_add_tool` never creates the `install-llvm-config` target (both the `install(TARGETS)` call and `add_llvm_install_targets` are gated on LLVM_BUILD_TOOLS in AddLLVM.cmake). LLVM_DISTRIBUTION_COMPONENTS errors out at configure time with "Specified distribution component 'llvm-config' doesn't have an install target". Fix: drop `llvm-config` from the distribution whitelist, and after `ninja install-distribution` completes, directly `ninja llvm-config` (force-build the excluded-from-ALL target) and `fs_extra::file::copy` the binary into the install prefix's `bin/` dir. Rust-side, co-located with the rest of the Windows logic. Still cleaner than the pre-rework YAML version: - No YAML file round-trip for `--extra-args` - No dead `LLVM_TOOL_LLVM_CONFIG_BUILD='On'` flag - All Windows-specific logic in one Rust file, not split - Uses install-distribution for everything that is distribution-aware (libs, headers, cmake-exports); only llvm-config takes the manual path
1 parent c8edbb5 commit 4c36376

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

solx-dev/src/llvm/platforms/shared.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,25 @@ pub fn shared_build_opts_coverage(enabled: bool) -> Vec<String> {
172172
/// never invokes any LLVM tool at runtime (it consumes LLVM as a library via
173173
/// inkwell), so linking them is pure waste. `LLVM_BUILD_TOOLS=Off` marks every
174174
/// tool `EXCLUDE_FROM_ALL`; `LLVM_INCLUDE_TOOLS=On` keeps `tools/` in the
175-
/// configure pass so the umbrella targets (`llvm-libraries`, `llvm-config`) are
176-
/// defined. `LLVM_DISTRIBUTION_COMPONENTS` whitelists the install set, which
175+
/// configure pass so the umbrella targets (`llvm-libraries` etc.) are defined.
176+
/// `LLVM_DISTRIBUTION_COMPONENTS` whitelists the install set, which
177177
/// `install-distribution` then honours — see #364.
178178
///
179-
/// `llvm-config` is included because `llvm-sys` shells out to it at Rust build
180-
/// time to discover include paths and link flags. `lld-*` is always included
181-
/// because `shared_build_opts_projects` always enables `lld`. `mlir-*` is
182-
/// included only when `enable_mlir` is true.
179+
/// `llvm-config` is deliberately **not** in the distribution list: with
180+
/// `LLVM_BUILD_TOOLS=Off`, `llvm_add_tool` never creates the `install-llvm-config`
181+
/// cmake target (both `install(TARGETS)` and `add_llvm_install_targets` are
182+
/// gated on `LLVM_BUILD_TOOLS`), so referencing it here errors at configure
183+
/// time. `llvm-sys` still needs `llvm-config` at Rust build time — the Windows
184+
/// builder builds it via direct `ninja llvm-config` and copies the binary into
185+
/// the install prefix after `install-distribution` completes.
186+
/// `lld-*` is always included because `shared_build_opts_projects` always
187+
/// enables `lld`. `mlir-*` is included only when `enable_mlir` is true.
183188
///
184189
pub fn windows_build_opts_distribution(enable_mlir: bool) -> Vec<String> {
185190
let mut components = vec![
186191
"llvm-libraries",
187192
"llvm-headers",
188193
"cmake-exports",
189-
"llvm-config",
190194
"lld-libraries",
191195
"lld-headers",
192196
"lld-cmake-exports",

solx-dev/src/llvm/platforms/x86_64_windows_gnu.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ pub fn build(
7878
// ~200 LLVM tool binaries solx doesn't use. See #364.
7979
crate::utils::ninja(llvm_build_final.as_ref(), "install-distribution")?;
8080

81+
// `llvm-config` is excluded from the distribution because LLVM_BUILD_TOOLS=Off
82+
// prevents its install target from ever being defined. Build and copy it by
83+
// hand so llvm-sys can find it at Rust build time.
84+
crate::utils::command(
85+
Command::new("ninja")
86+
.arg("-C")
87+
.arg(&*llvm_build_final_str)
88+
.arg("llvm-config"),
89+
"Building llvm-config",
90+
)?;
91+
let llvm_config_source = llvm_build_final.join("bin").join("llvm-config.exe");
92+
let llvm_config_dest_dir = llvm_target_final.join("bin");
93+
std::fs::create_dir_all(&llvm_config_dest_dir)?;
94+
fs_extra::file::copy(
95+
crate::utils::path_windows_to_unix(llvm_config_source)?,
96+
crate::utils::path_windows_to_unix(llvm_config_dest_dir.join("llvm-config.exe"))?,
97+
&fs_extra::file::CopyOptions::default(),
98+
)?;
99+
81100
let libstdcpp_source_path = match std::env::var("LIBSTDCPP_SOURCE_PATH") {
82101
Ok(libstdcpp_source_path) => PathBuf::from(libstdcpp_source_path),
83102
Err(error) => anyhow::bail!(

0 commit comments

Comments
 (0)