Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-c-api) Set the install name of the dylib to @rpath. #474

Merged
merged 1 commit into from
May 29, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented May 29, 2019

$ objdump -macho -dylib-id libwasmer_runtime_c_api.dylib
libwasmer_runtime_c_api.dylib:
/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib

we observe that the dylib ID (aka install name) is set to
/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib,
which is valid only in the context of CircleCI.

This patch changes the dylib ID to
@rpath/libwasmer_runtime_c_api.dylib, which can be then changed by
the linker option -rpath (use -Wl,-rpath,$value with the compiler
to send the -rpath value to the linker).

This is super useful when dynamically linking libraries against
another language. Having the dylib ID already set to @rpath avoid any
build system to call install_name_tool manually, which isn't always
possible (e.g. in Go with cgo where we can only pass options to the
compiler with LDFLAGS, it's impossible to run any arbitrary command).

@Hywan Hywan added bug Something isn't working 📦 lib-c-api About wasmer-c-api labels May 29, 2019
@Hywan Hywan requested a review from syrusakbary May 29, 2019 14:12
```sh
$ objdump -macho -dylib-id libwasmer_runtime_c_api.dylib
libwasmer_runtime_c_api.dylib:
/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib
```

we observe that the dylib ID (aka install name) is set to
`/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib`,
which is valid only in the context of CircleCI.

This patch changes the dylib ID to
`@rpath/libwasmer_runtime_c_api.dylib`, which can be then changed by
the linker option `-rpath` (use `-Wl,-rpath,$value` with the compiler
to send the `-rpath` value to the linker).

This is super useful when dynamically linking libraries against
another language.
@Hywan Hywan force-pushed the fix-runtime-c-api-dylib branch from cc1a846 to ff5d50b Compare May 29, 2019 14:14
Hywan added a commit to Hywan/go-ext-wasm that referenced this pull request May 29, 2019
This patch depends on wasmerio/wasmer#474,
which fixes the dylib ID for macOS to use `@rpath`.

This patch renames the `just go` recipe to `just build`.

The `just build` recipe compiles the Rust dynamic library only when
required, i.e. when the `libwasmer_runtime_c_api.*` file is absent
from the source tree.

This patch also updates `bridge.go` to specify the `rpath` to the
linker with `-Wl,-rpath`. On macOS, the solution would be to set
`rpath` to `@executable_path` but since
https://nvd.nist.gov/vuln/detail/CVE-2018-6574, some flags are
disabled (see https://github.com/golang/go/wiki/InvalidFlag for more
information). Hopefully for us, cgo has this special `${SRCDIR}`
variable (see
https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command), which
is a possible alternative.
@Hywan
Copy link
Contributor Author

Hywan commented May 29, 2019

bors try

bors bot added a commit that referenced this pull request May 29, 2019
@bors
Copy link
Contributor

bors bot commented May 29, 2019

@Hywan
Copy link
Contributor Author

Hywan commented May 29, 2019

bors r+

bors bot added a commit that referenced this pull request May 29, 2019
474: fix(runtime-c-api) Set the install name of the dylib to `@rpath`. r=Hywan a=Hywan

```sh
$ objdump -macho -dylib-id libwasmer_runtime_c_api.dylib
libwasmer_runtime_c_api.dylib:
/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib
```

we observe that the dylib ID (aka install name) is set to
`/Users/distiller/project/target/release/deps/libwasmer_runtime_c_api.dylib`,
which is valid only in the context of CircleCI.

This patch changes the dylib ID to
`@rpath/libwasmer_runtime_c_api.dylib`, which can be then changed by
the linker option `-rpath` (use `-Wl,-rpath,$value` with the compiler
to send the `-rpath` value to the linker).

This is super useful when dynamically linking libraries against
another language. Having the dylib ID already set to `@rpath` avoid any
build system to call `install_name_tool` manually, which isn't always
possible (e.g. in Go with cgo where we can only pass options to the
compiler with `LDFLAGS`, it's impossible to run any arbitrary command).

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request May 29, 2019
12: feat(runtime) Use dynamic libraries instead of compiling the runtime r=Hywan a=Hywan

Dependency: wasmerio/wasmer#474.

This sequence of patches aims at using dynamic libraries for the runtime. It avoids the need to compile the runtime (with `rustc`/`cargo`) when installing the Go library.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented May 29, 2019

@bors bors bot merged commit ff5d50b into wasmerio:master May 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-c-api About wasmer-c-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants