Skip to content

Commit

Permalink
Merge pull request #5 from habitat-sh/jj/ld64
Browse files Browse the repository at this point in the history
LD64 Wrapper Support for MacOS
  • Loading branch information
sajjaphani authored Aug 26, 2024
2 parents 727fb47 + 5dc137a commit 9defbe9
Show file tree
Hide file tree
Showing 4 changed files with 2,215 additions and 30 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ env:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
toolchain:
os: [ubuntu-latest, macos-latest]
architecture: [x64, arm64]
toolchain:
- 1.75.0
exclude:
- os: macos-latest
architecture: x64

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
.vscode
64 changes: 37 additions & 27 deletions src/bin/hab-ld-wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,14 +1116,24 @@ mod tests {
}
std::fs::File::create(path).unwrap();
}
fn shared_lib_name(name: impl AsRef<str>) -> String {
#[cfg(target_os = "macos")]
{
return format!("lib{}.dylib", name.as_ref());
}
#[cfg(target_os = "linux")]
{
return format!("lib{}.so", name.as_ref());
}
}

mod complete_ld_link_mode {
use hab_pkg_wrappers::env::CommonEnvironment;
use tempdir::TempDir;

use crate::{parse_linker_arguments, LDEnvironment};

use super::touch;
use super::{shared_lib_name, touch};

// This scenario checks that whatever directory is present in the LD_RUN_PATH will be added
// as an rpath argument regardless of if the library path is provided to the linker and regardless
Expand All @@ -1141,7 +1151,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);
let libx_search_path = temp_dir
.path()
Expand All @@ -1152,7 +1162,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libx_shared = libx_search_path.join("libx.so");
let libx_shared = libx_search_path.join(shared_lib_name("x"));
touch(libx_shared);
let libz_search_path = temp_dir
.path()
Expand All @@ -1163,7 +1173,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libz_shared = libz_search_path.join("libz.so");
let libz_shared = libz_search_path.join(shared_lib_name("z"));
touch(libz_shared);
let libm_search_path = temp_dir
.path()
Expand Down Expand Up @@ -1216,7 +1226,7 @@ mod tests {
}

mod minimal_ld_link_mode {
use super::touch;
use super::{shared_lib_name, touch};
use hab_pkg_wrappers::env::CommonEnvironment;
use tempdir::TempDir;

Expand All @@ -1236,7 +1246,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-lc -L {}", libc_search_path.display());
Expand Down Expand Up @@ -1323,7 +1333,7 @@ mod tests {
.join("lib");
let libc_static = libc_search_path.join("libc.a");
touch(libc_static);
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!(
Expand Down Expand Up @@ -1380,7 +1390,7 @@ mod tests {
.join("lib");
let libc_static = libc_search_path.join("libc.a");
touch(libc_static);
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-lc -L {}", libc_search_path.display());
Expand Down Expand Up @@ -1424,7 +1434,7 @@ mod tests {
.join("lib");
let libc_static = libc_search_path.join("libc.a");
touch(libc_static);
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-Bstatic -lc -L {}", libc_search_path.display());
Expand Down Expand Up @@ -1456,7 +1466,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-lc -L {0} -rpath {0}", libc_search_path.display());
Expand Down Expand Up @@ -1488,7 +1498,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-lc -L {}/../lib", libc_search_path.display());
Expand Down Expand Up @@ -1527,7 +1537,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!(
Expand Down Expand Up @@ -1569,7 +1579,7 @@ mod tests {
.join("cache")
.join("src")
.join("openssl");
let libcrypto_shared = build_dir.join("libcrypto.so");
let libcrypto_shared = build_dir.join(shared_lib_name("crypto"));
touch(&libcrypto_shared);

// Passed as -l flag
Expand Down Expand Up @@ -1668,7 +1678,7 @@ mod tests {
.join("glibc")
.join("old-version")
.join("release");
let old_libc_shared = old_install_prefix_dir.join("libc.so");
let old_libc_shared = old_install_prefix_dir.join(shared_lib_name("c"));
touch(&old_libc_shared);

let install_prefix_dir = temp_dir
Expand All @@ -1685,7 +1695,7 @@ mod tests {
.join("cache")
.join("src")
.join("glibc");
let new_libc_shared = build_dir.join("libc.so");
let new_libc_shared = build_dir.join(shared_lib_name("c"));
touch(&new_libc_shared);

// New library passed via build search path
Expand Down Expand Up @@ -1845,7 +1855,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libstdcxx_shared = libstdcxx_search_path.join("libstdc++.so");
let libstdcxx_shared = libstdcxx_search_path.join(shared_lib_name("stdc++"));
touch(&libstdcxx_shared);
let libstdcxx_libs_search_path = temp_dir
.path()
Expand All @@ -1856,7 +1866,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libstdcxx_libs_shared = libstdcxx_libs_search_path.join("libstdc++.so");
let libstdcxx_libs_shared = libstdcxx_libs_search_path.join(shared_lib_name("stdc++"));
touch(&libstdcxx_libs_shared);

// This is the case where gcc and gcc-libs are only a build dep
Expand Down Expand Up @@ -1974,7 +1984,7 @@ mod tests {
.join("lib");
let libc_static = libc_search_path.join("libc.a");
touch(libc_static);
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("--as-needed -lc -L {}", libc_search_path.display());
Expand Down Expand Up @@ -2019,7 +2029,7 @@ mod tests {
.join("lib");
let libc_static = libc_search_path.join("libc.a");
touch(libc_static);
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("--as-needed -lc -L {}", libc_search_path.display());
Expand Down Expand Up @@ -2069,7 +2079,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(&libc_shared);
let libz_search_path = temp_dir
.path()
Expand All @@ -2080,7 +2090,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libz_shared = libz_search_path.join("libz.so");
let libz_shared = libz_search_path.join(shared_lib_name("z"));
touch(&libz_shared);

// without ld run path hint
Expand Down Expand Up @@ -2156,7 +2166,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(&libc_shared);
let libz_search_path = temp_dir
.path()
Expand All @@ -2167,7 +2177,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libz_shared = libz_search_path.join("libz.so");
let libz_shared = libz_search_path.join(shared_lib_name("z"));
let libz_static = libz_search_path.join("libz.a");
touch(&libz_shared);
touch(&libz_static);
Expand Down Expand Up @@ -2205,7 +2215,7 @@ mod tests {
fn impure_library_search_path_filtering() {
let temp_dir = TempDir::new("ld-wrapper-test").unwrap();
let libc_search_path = temp_dir.path().join("usr").join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments = format!("-lc -L {0} -L{0} -L{0}/../../usr/lib -L {0}/../../usr/lib -L{0}/../../hab/pkgs/core/glibc/version/release/lib -lm", libc_search_path.display());
Expand Down Expand Up @@ -2235,7 +2245,7 @@ mod tests {
fn impure_absolute_library_path_filtering() {
let temp_dir = TempDir::new("ld-wrapper-test").unwrap();
let impure_libz_search_path = temp_dir.path().join("usr").join("lib");
let impure_libz_shared = impure_libz_search_path.join("libz.so");
let impure_libz_shared = impure_libz_search_path.join(shared_lib_name("z"));
touch(&impure_libz_shared);

let libc_search_path = temp_dir
Expand All @@ -2247,7 +2257,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(&libc_shared);

let raw_link_arguments = format!(
Expand Down Expand Up @@ -2438,7 +2448,7 @@ mod tests {
.join("version")
.join("release")
.join("lib");
let libc_shared = libc_search_path.join("libc.so");
let libc_shared = libc_search_path.join(shared_lib_name("c"));
touch(libc_shared);

let raw_link_arguments =
Expand Down
Loading

0 comments on commit 9defbe9

Please sign in to comment.