revive llvm builder utility (#154)

Pre-eliminary support for LLVM releases and resolc binary releases by streamlining the build process for all supported hosts platforms.

- Introduce the revive-llvm-builder crate with the revive-llvm builder utilty.
- Do not rely on the LLVM dependency in $PATH to decouple the system LLVM installation from the LLVM host dependency.
- Fix the emscripten build by decoupling the host and native LLVM dependencies. Thus allowing a single LLVM emscripten release that can be used on any host platform.
- An example Dockerfile building an alpine container with a fully statically linked resolc ELF binary.
- Remove the Debian builder utilities and workflow.
This commit is contained in:
Cyrill Leutwiler
2025-01-13 15:58:27 +01:00
committed by GitHub
parent fde9edab10
commit 7f81f37e0c
65 changed files with 4847 additions and 557 deletions
+1
View File
@@ -13,3 +13,4 @@ libc = { workspace = true }
[build-dependencies]
cc = { workspace = true }
revive-build-utils = { workspace = true }
+23 -32
View File
@@ -1,34 +1,16 @@
use std::{
env,
path::{Path, PathBuf},
};
fn set_rustc_link_flags() {
let llvm_lib_path = match std::env::var(revive_build_utils::REVIVE_LLVM_TARGET_PREFIX) {
Ok(path) => std::path::PathBuf::from(path).join("lib"),
_ => revive_build_utils::llvm_lib_dir(),
};
const LLVM_LINK_PREFIX: &str = "LLVM_LINK_PREFIX";
fn locate_llvm_config() -> PathBuf {
let prefix = env::var_os(LLVM_LINK_PREFIX)
.map(|p| PathBuf::from(p).join("bin"))
.unwrap_or_default();
prefix.join("llvm-config")
}
fn llvm_config(llvm_config_path: &Path, arg: &str) -> String {
let output = std::process::Command::new(llvm_config_path)
.args([arg])
.output()
.unwrap_or_else(|_| panic!("`llvm-config {arg}` failed"));
String::from_utf8(output.stdout)
.unwrap_or_else(|_| panic!("output of `llvm-config {arg}` should be utf8"))
}
fn set_rustc_link_flags(llvm_config_path: &Path) {
println!(
"cargo:rustc-link-search=native={}",
llvm_config(llvm_config_path, "--libdir")
llvm_lib_path.to_string_lossy()
);
for lib in [
// These are required by ld.lld
"lldELF",
"lldCommon",
"lldMachO",
@@ -91,18 +73,27 @@ fn set_rustc_link_flags(llvm_config_path: &Path) {
}
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default();
if target_os == "linux" {
println!("cargo:rustc-link-lib=dylib=stdc++");
println!("cargo:rustc-link-lib=tinfo");
if target_env == "musl" {
println!("cargo:rustc-link-lib=static=c++");
} else {
println!("cargo:rustc-link-lib=dylib=stdc++");
}
}
}
fn main() {
println!("cargo:rerun-if-env-changed={}", LLVM_LINK_PREFIX);
println!(
"cargo:rerun-if-env-changed={}",
revive_build_utils::REVIVE_LLVM_HOST_PREFIX
);
println!(
"cargo:rerun-if-env-changed={}",
revive_build_utils::REVIVE_LLVM_TARGET_PREFIX
);
let llvm_config_path = locate_llvm_config();
llvm_config(&llvm_config_path, "--cxxflags")
revive_build_utils::llvm_cxx_flags()
.split_whitespace()
.fold(&mut cc::Build::new(), |builder, flag| builder.flag(flag))
.flag("-Wno-unused-parameter")
@@ -110,7 +101,7 @@ fn main() {
.file("src/linker.cpp")
.compile("liblinker.a");
set_rustc_link_flags(&llvm_config_path);
set_rustc_link_flags();
println!("cargo:rerun-if-changed=build.rs");
}