From b0ef2dc6a4c488f8ee09721e99dc7ecdbd0a3032 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:27:18 +0900 Subject: [PATCH 01/11] Refactor `build.rs` --- build.rs | 17 +++++++++-------- tools/setup.sh | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/build.rs b/build.rs index bf4e0ff..5046c23 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() { diff --git a/tools/setup.sh b/tools/setup.sh index 65d8d71..7adec6f 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -5,9 +5,9 @@ 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 +echo TABLEGEN_180_PREFIX=$(brew --prefix llvm@$llvm_version) >>$GITHUB_ENV +echo PATH=$TABLEGEN_180_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 From b2cc4cdc5e467d3956849bc7880253014929aa37 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:28:57 +0900 Subject: [PATCH 02/11] Refactor format string --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 5046c23..698441d 100644 --- a/build.rs +++ b/build.rs @@ -101,7 +101,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())) From 2a8687f582ca64e3c36a5fa5b814d13071595373 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:29:37 +0900 Subject: [PATCH 03/11] Use latest macOS --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 0412d1b5b42c15e3bb09df91e84077d52bce4921 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:31:05 +0900 Subject: [PATCH 04/11] Fix version number in environment variable --- tools/setup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/setup.sh b/tools/setup.sh index 7adec6f..87cdd79 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -7,7 +7,7 @@ llvm_version=19 brew update brew install llvm@$llvm_version -echo TABLEGEN_180_PREFIX=$(brew --prefix llvm@$llvm_version) >>$GITHUB_ENV -echo PATH=$TABLEGEN_180_PREFIX/bin:$PATH >>$GITHUB_ENV +echo TABLEGEN_190_PREFIX=$(brew --prefix llvm@$llvm_version) >>$GITHUB_ENV +echo PATH=$TABLEGEN_190_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 From 9f23f26c6681ccc93c5430c2c308955f301eb758 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:35:08 +0900 Subject: [PATCH 05/11] Fix setup.sh --- tools/setup.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/setup.sh b/tools/setup.sh index 87cdd79..3e68f82 100755 --- a/tools/setup.sh +++ b/tools/setup.sh @@ -7,7 +7,9 @@ llvm_version=19 brew update brew install llvm@$llvm_version -echo TABLEGEN_190_PREFIX=$(brew --prefix llvm@$llvm_version) >>$GITHUB_ENV -echo PATH=$TABLEGEN_190_PREFIX/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 From 69421cc5be2246990325ededb1e2f34ac2596ace Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:41:04 +0900 Subject: [PATCH 06/11] Refactor `build.rs` --- build.rs | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/build.rs b/build.rs index 698441d..a88f3f2 100644 --- a/build.rs +++ b/build.rs @@ -37,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={}", parse_library_name(name)?); } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -60,14 +55,7 @@ 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); @@ -78,8 +66,6 @@ fn run() -> Result<(), Box> { println!("cargo:rustc-link-lib={}", name); } - std::env::set_var("CXXFLAGS", llvm_config("--cxxflags")?); - std::env::set_var("CFLAGS", llvm_config("--cflags")?); println!("cargo:rustc-link-search={}", &env::var("OUT_DIR")?); cc::Build::new() @@ -144,10 +130,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)) } From 7d566568bb9cc2b28f0c74ce9428c055922127e9 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:49:11 +0900 Subject: [PATCH 07/11] Revert "Refactor `build.rs`" This reverts commit 69421cc5be2246990325ededb1e2f34ac2596ace. --- build.rs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index a88f3f2..698441d 100644 --- a/build.rs +++ b/build.rs @@ -37,9 +37,14 @@ 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(' ') { - println!("cargo:rustc-link-lib={}", parse_library_name(name)?); + if let Some(name) = trim_library_name(name) { + println!("cargo:rustc-link-lib={}", name); + } } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -55,7 +60,14 @@ fn run() -> Result<(), Box> { ); println!( "cargo:rustc-link-lib={}", - parse_library_name(path.file_name().unwrap().to_str().unwrap())? + path.file_name() + .unwrap() + .to_str() + .unwrap() + .split_once('.') + .unwrap() + .0 + .trim_start_matches("lib") ); } else { println!("cargo:rustc-link-lib={}", flag); @@ -66,6 +78,8 @@ fn run() -> Result<(), Box> { println!("cargo:rustc-link-lib={}", name); } + std::env::set_var("CXXFLAGS", llvm_config("--cxxflags")?); + std::env::set_var("CFLAGS", llvm_config("--cflags")?); println!("cargo:rustc-link-search={}", &env::var("OUT_DIR")?); cc::Build::new() @@ -130,8 +144,10 @@ fn llvm_config(argument: &str) -> Result> { .to_string()) } -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)) +fn trim_library_name(name: &str) -> Option<&str> { + if let Some(name) = name.strip_prefix("lib") { + name.strip_suffix(".a") + } else { + None + } } From 22800701db69ea92ff0aa1a1712e4cd3bc282552 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 22:53:48 +0900 Subject: [PATCH 08/11] Reapply "Refactor `build.rs`" This reverts commit 7d566568bb9cc2b28f0c74ce9428c055922127e9. --- build.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/build.rs b/build.rs index 698441d..c737825 100644 --- a/build.rs +++ b/build.rs @@ -37,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={}", parse_library_name(name)?); } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -60,14 +55,7 @@ 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); @@ -144,10 +132,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)) } From 08bec1028fe84c556b7253c06cc26a989e1f5a00 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 23:09:08 +0900 Subject: [PATCH 09/11] Revert "Reapply "Refactor `build.rs`"" This reverts commit 22800701db69ea92ff0aa1a1712e4cd3bc282552. --- build.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/build.rs b/build.rs index c737825..698441d 100644 --- a/build.rs +++ b/build.rs @@ -37,9 +37,14 @@ 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(' ') { - println!("cargo:rustc-link-lib={}", parse_library_name(name)?); + if let Some(name) = trim_library_name(name) { + println!("cargo:rustc-link-lib={}", name); + } } for flag in llvm_config("--system-libs")?.trim().split(' ') { @@ -55,7 +60,14 @@ fn run() -> Result<(), Box> { ); println!( "cargo:rustc-link-lib={}", - parse_library_name(path.file_name().unwrap().to_str().unwrap())? + path.file_name() + .unwrap() + .to_str() + .unwrap() + .split_once('.') + .unwrap() + .0 + .trim_start_matches("lib") ); } else { println!("cargo:rustc-link-lib={}", flag); @@ -132,8 +144,10 @@ fn llvm_config(argument: &str) -> Result> { .to_string()) } -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)) +fn trim_library_name(name: &str) -> Option<&str> { + if let Some(name) = name.strip_prefix("lib") { + name.strip_suffix(".a") + } else { + None + } } From ffe5ae2c499e22cfc4884bb2a4f21db3f32e9da1 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 23:11:28 +0900 Subject: [PATCH 10/11] Reapply "Reapply "Refactor `build.rs`"" This reverts commit 08bec1028fe84c556b7253c06cc26a989e1f5a00. --- build.rs | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/build.rs b/build.rs index 698441d..9351510 100644 --- a/build.rs +++ b/build.rs @@ -37,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(' ') { @@ -60,14 +55,7 @@ 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); @@ -144,10 +132,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)) } From 5089b04c0e2dc5f641ea43b48936b9c26f9b5964 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Tue, 24 Sep 2024 23:26:20 +0900 Subject: [PATCH 11/11] Link libffi --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 9351510..ee4f3b1 100644 --- a/build.rs +++ b/build.rs @@ -62,6 +62,8 @@ fn run() -> Result<(), Box> { } } + println!("cargo:rustc-link-lib=ffi"); + if let Some(name) = get_system_libcpp() { println!("cargo:rustc-link-lib={}", name); }