NAC3 on OpenBSD #342

Closed
opened 2023-10-18 01:31:48 +08:00 by sb10q · 1 comment
Owner
  • llvm-config is needed. Can be compiled manually with "make llvm-config" and copying the binary to the prefix.
  • llvm-sys needs the patch below:
diff --git a/build.rs b/build.rs
index ab90312..c8252aa 100644
--- a/build.rs
+++ b/build.rs
@@ -296,7 +296,10 @@ fn get_system_libraries(kind: LibraryKind) -> Vec<String> {
             } else {
                 if flag.starts_with("-l") {
                     // Linker flags style, -lfoo
-                    return flag[2..].to_owned();
+                    // For some reason, on OpenBSD llvm-config sometimes emits
+                    // broken linker flags such as "-lz.so.7.0"
+                    let dotidx = flag.find(".").unwrap_or(flag.len());
+                    return flag[2..dotidx].to_owned();
                 }
 
                 let maybe_lib = Path::new(&flag);
@@ -334,6 +337,8 @@ fn get_system_libcpp() -> Option<&'static str> {
         Some("c++")
     } else if target_os_is("freebsd") {
         Some("c++")
+    } else if target_os_is("openbsd") {
+        Some("c++")
     } else if target_env_is("musl") {
         // The one built with musl.
         Some("c++")
@@ -608,6 +613,9 @@ fn main() {
     for name in get_system_libraries(kind) {
         println!("cargo:rustc-link-lib={}={}", sys_lib_kind.string(), name);
     }
+    if target_os_is("openbsd") {
+        println!("cargo:rustc-link-search=/usr/local/lib");
+    }
 
     let use_debug_msvcrt = env::var_os(&*ENV_USE_DEBUG_MSVCRT).is_some();
     if target_env_is("msvc") && (use_debug_msvcrt || is_llvm_debug()) {
~

llvm-sys can be overriden with:

diff --git a/Cargo.lock b/Cargo.lock
index 67cd464..992a38b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -509,9 +509,7 @@ checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0"
 
 [[package]]
 name = "llvm-sys"
-version = "140.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fe48b87b95ad1b3eeca563010aadbb427b3d3e89c1f78fe21acd39846be5c7d4"
+version = "140.1.2"
 dependencies = [
  "cc",
  "lazy_static",
diff --git a/Cargo.toml b/Cargo.toml
index d3f348a..03ccf77 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,3 +11,7 @@ members = [
 
 [profile.release]
 debug = true
+
+[patch.crates-io]
+llvm-sys = { path = "/home/sb/llvm-sys.rs" }
+
  • nac3standalone works
  • nac3artiq breaks with:
assertion "PrettyStackTraceHead == this && "Pretty stack trace entry destruction is out of order"" failed: file "/home/sb/llvm/llvm-14.0.6.src/lib/Support/PrettyStackTrace.cpp", line 230, function "~PrettyStackTraceEntry"
fish: Job 1, 'python3 demo.py' terminated by signal SIGABRT (Abort)

I have no solution for this one.

* llvm-config is needed. Can be compiled manually with "make llvm-config" and copying the binary to the prefix. * llvm-sys needs the patch below: ``` diff --git a/build.rs b/build.rs index ab90312..c8252aa 100644 --- a/build.rs +++ b/build.rs @@ -296,7 +296,10 @@ fn get_system_libraries(kind: LibraryKind) -> Vec<String> { } else { if flag.starts_with("-l") { // Linker flags style, -lfoo - return flag[2..].to_owned(); + // For some reason, on OpenBSD llvm-config sometimes emits + // broken linker flags such as "-lz.so.7.0" + let dotidx = flag.find(".").unwrap_or(flag.len()); + return flag[2..dotidx].to_owned(); } let maybe_lib = Path::new(&flag); @@ -334,6 +337,8 @@ fn get_system_libcpp() -> Option<&'static str> { Some("c++") } else if target_os_is("freebsd") { Some("c++") + } else if target_os_is("openbsd") { + Some("c++") } else if target_env_is("musl") { // The one built with musl. Some("c++") @@ -608,6 +613,9 @@ fn main() { for name in get_system_libraries(kind) { println!("cargo:rustc-link-lib={}={}", sys_lib_kind.string(), name); } + if target_os_is("openbsd") { + println!("cargo:rustc-link-search=/usr/local/lib"); + } let use_debug_msvcrt = env::var_os(&*ENV_USE_DEBUG_MSVCRT).is_some(); if target_env_is("msvc") && (use_debug_msvcrt || is_llvm_debug()) { ~ ``` llvm-sys can be overriden with: ``` diff --git a/Cargo.lock b/Cargo.lock index 67cd464..992a38b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -509,9 +509,7 @@ checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" [[package]] name = "llvm-sys" -version = "140.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe48b87b95ad1b3eeca563010aadbb427b3d3e89c1f78fe21acd39846be5c7d4" +version = "140.1.2" dependencies = [ "cc", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index d3f348a..03ccf77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,7 @@ members = [ [profile.release] debug = true + +[patch.crates-io] +llvm-sys = { path = "/home/sb/llvm-sys.rs" } + ``` * nac3standalone works * nac3artiq breaks with: ``` assertion "PrettyStackTraceHead == this && "Pretty stack trace entry destruction is out of order"" failed: file "/home/sb/llvm/llvm-14.0.6.src/lib/Support/PrettyStackTrace.cpp", line 230, function "~PrettyStackTraceEntry" fish: Job 1, 'python3 demo.py' terminated by signal SIGABRT (Abort) ``` I have no solution for this one.
Author
Owner

Now working after some BSD updates. llvm-sys patch is also upstream.

Now working after some BSD updates. llvm-sys patch is also upstream.
sb10q closed this issue 2024-03-01 15:57:11 +08:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/nac3#342
No description provided.