diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cb26803..b4258d8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,7 @@ jobs: matrix: os: - ubuntu-latest - - macos-14 + - macos-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/build.rs b/build.rs index bf4e0ff..ee4f3b1 100644 --- a/build.rs +++ b/build.rs @@ -6,14 +6,15 @@ use std::{ str, }; -#[cfg(feature = "llvm16-0")] -const LLVM_MAJOR_VERSION: usize = 16; -#[cfg(feature = "llvm17-0")] -const LLVM_MAJOR_VERSION: usize = 17; -#[cfg(feature = "llvm18-0")] -const LLVM_MAJOR_VERSION: usize = 18; -#[cfg(feature = "llvm19-0")] -const LLVM_MAJOR_VERSION: usize = 19; +const LLVM_MAJOR_VERSION: usize = if cfg!(feature = "llvm16-0") { + 16 +} else if cfg!(feature = "llvm17-0") { + 17 +} else if cfg!(feature = "llvm18-0") { + 18 +} else { + 19 +}; fn main() { if let Err(error) = run() { @@ -36,14 +37,9 @@ fn run() -> Result<(), Box> { println!("cargo:rerun-if-changed=wrapper.h"); println!("cargo:rerun-if-changed=cc"); println!("cargo:rustc-link-search={}", llvm_config("--libdir")?); - println!("cargo:rustc-link-lib=static=LLVMCore"); - println!("cargo:rustc-link-lib=static=LLVMSupport"); - println!("cargo:rustc-link-lib=static=LLVMTableGen"); for name in llvm_config("--libnames")?.trim().split(' ') { - if let Some(name) = trim_library_name(name) { - println!("cargo:rustc-link-lib={}", name); - } + println!("cargo:rustc-link-lib=static={}", parse_library_name(name)?); } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -59,20 +55,15 @@ fn run() -> Result<(), Box> { ); println!( "cargo:rustc-link-lib={}", - path.file_name() - .unwrap() - .to_str() - .unwrap() - .split_once('.') - .unwrap() - .0 - .trim_start_matches("lib") + parse_library_name(path.file_name().unwrap().to_str().unwrap())? ); } else { println!("cargo:rustc-link-lib={}", flag); } } + println!("cargo:rustc-link-lib=ffi"); + if let Some(name) = get_system_libcpp() { println!("cargo:rustc-link-lib={}", name); } @@ -100,7 +91,7 @@ fn run() -> Result<(), Box> { bindgen::builder() .header("wrapper.h") - .clang_arg(format!("-I{}", "cc/include")) + .clang_arg("-Icc/include") .clang_arg(format!("-I{}", llvm_config("--includedir")?)) .default_enum_style(bindgen::EnumVariation::ModuleConsts) .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) @@ -143,10 +134,8 @@ fn llvm_config(argument: &str) -> Result> { .to_string()) } -fn trim_library_name(name: &str) -> Option<&str> { - if let Some(name) = name.strip_prefix("lib") { - name.strip_suffix(".a") - } else { - None - } +fn parse_library_name(name: &str) -> Result<&str, String> { + name.strip_prefix("lib") + .and_then(|name| name.split('.').next()) + .ok_or_else(|| format!("failed to parse library name: {}", name)) } diff --git a/tools/setup.sh b/tools/setup.sh index 65d8d71..3e68f82 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -5,9 +5,11 @@ set -e llvm_version=19 brew update -brew install llvm@$llvm_version z3 +brew install llvm@$llvm_version -echo TABLEGEN_190_PREFIX=$(brew --prefix)/opt/llvm@$llvm_version >>$GITHUB_ENV -echo PATH=$(brew --prefix)/opt/llvm@$llvm_version/bin:$PATH >>$GITHUB_ENV +llvm_prefix=$(brew --prefix llvm@$llvm_version) + +echo TABLEGEN_190_PREFIX=$llvm_prefix >>$GITHUB_ENV +echo PATH=$llvm_prefix/bin:$PATH >>$GITHUB_ENV echo LIBRARY_PATH=$(brew --prefix)/lib:$LIBRARY_PATH >>$GITHUB_ENV echo LD_LIBRARY_PATH=$(brew --prefix)/lib:$LD_LIBRARY_PATH >>$GITHUB_ENV