Skip to content

Commit

Permalink
feat: Configure soname, install_name, out-implib etc. for the C…
Browse files Browse the repository at this point in the history
… API.

This patch uses `cdylib-link-lines` to “configure” the cdylib
correctly.
  • Loading branch information
Hywan committed Jul 6, 2021
1 parent ffb988c commit 4b783ff
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
rustflags = [
# Put the VM functions in the dynamic symbol table.
"-C", "link-arg=-Wl,-E",
# Fix the SONAME, required by CMake, see https://github.com/wasmerio/wasmer/issues/2429.
"-C", "link-arg=-Wl,-soname,libwasmer.so",
]
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ native = ["dylib"]

[build-dependencies]
cbindgen = "0.18"
cdylib-link-lines = "0.1"
26 changes: 26 additions & 0 deletions lib/c-api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fn main() {

build_wasm_c_api_headers(&crate_dir, &out_dir);
build_inline_c_env_vars();
build_cdylib();
}

/// Check whether we should build the C API headers or set `inline-c` up.
Expand Down Expand Up @@ -298,3 +299,28 @@ fn build_inline_c_env_vars() {
}
);
}

fn build_cdylib() {
// Configure the `soname`, `install_name`, `current_version`,
// `out-implib`, `output-def` etc. for as much platforms as
// possible.
cdylib_link_lines::shared_object_link_args(
"wasmer",
&env::var("CARGO_PKG_VERSION_MAJOR").unwrap(),
&env::var("CARGO_PKG_VERSION_MINOR").unwrap(),
&env::var("CARGO_PKG_VERSION_PATCH").unwrap(),
&env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
&env::var("CARGO_CFG_TARGET_OS").unwrap(),
&env::var("CARGO_CFG_TARGET_ENV").unwrap(),
"/usr/local/lib".into(),
env::var_os("CARGO_TARGET_DIR").map_or(
{
let manifest_dir: PathBuf = env::var_os("CARGO_MANIFEST_DIR").unwrap().into();
manifest_dir
.join("target")
.join(env::var("PROFILE").unwrap())
},
Into::into,
),
);
}

0 comments on commit 4b783ff

Please sign in to comment.