Skip to content

Commit

Permalink
chore: Fix errors to be able to build on musl
Browse files Browse the repository at this point in the history
  • Loading branch information
jubianchi committed Jan 27, 2021
1 parent cfc8f04 commit 5962d3f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
32 changes: 24 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
ifneq ($(OS), Windows_NT)
ARCH := $(shell uname -m)
UNAME_S := $(shell uname -s)
LIBC ?= $(shell ldd 2>&1 | grep -o musl | head -n1)
else
# We can assume, if in windows it will likely be in x86_64
ARCH := x86_64
UNAME_S :=
UNAME_S :=
LIBC ?=
endif

# Which compilers we build. These have dependencies that may not be on the system.
Expand Down Expand Up @@ -38,14 +40,21 @@ ifeq ($(ARCH), x86_64)
test_compilers_engines += cranelift-jit
# LLVM could be enabled if not in Windows
ifneq ($(OS), Windows_NT)
# Native engine doesn't work on Windows yet.
test_compilers_engines += cranelift-native
ifneq ($(LIBC), musl)
# Native engine doesn't work on Windows and musl yet.
test_compilers_engines += cranelift-native
endif
# Singlepass doesn't work yet on Windows.
compilers += singlepass
# Singlepass doesn't work with the native engine.
test_compilers_engines += singlepass-jit
ifneq (, $(findstring llvm,$(compilers)))
test_compilers_engines += llvm-jit llvm-native
test_compilers_engines += llvm-jit

ifneq ($(LIBC), musl)
# Native engine doesn't work on musl yet.
test_compilers_engines += llvm-native
endif
endif
endif
endif
Expand Down Expand Up @@ -79,9 +88,9 @@ compilers := $(filter-out ,$(compilers))
test_compilers_engines := $(filter-out ,$(test_compilers_engines))

ifneq ($(OS), Windows_NT)
bold := $(shell tput bold)
green := $(shell tput setaf 2)
reset := $(shell tput sgr0)
bold := $(shell tput bold 2>/dev/null || echo -n '')
green := $(shell tput setaf 2 2>/dev/null || echo -n '')
reset := $(shell tput sgr0 2>/dev/null || echo -n '')
endif


Expand All @@ -90,6 +99,10 @@ compiler_features := --features "$(compiler_features_spaced)"

HOST_TARGET=$(shell rustup show | grep 'Default host: ' | cut -d':' -f2 | tr -d ' ')

ifneq (, $(LIBC))
$(info C standard library: $(bold)$(green)$(LIBC)$(reset))
endif

$(info Host target: $(bold)$(green)$(HOST_TARGET)$(reset))
$(info Available compilers: $(bold)$(green)${compilers}$(reset))
$(info Compilers features: $(bold)$(green)${compiler_features}$(reset))
Expand Down Expand Up @@ -376,7 +389,10 @@ ifeq ($(UNAME_S), Darwin)
# Fix the rpath for the dylib
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
else
cp target/release/libwasmer_c_api.so package/lib/libwasmer.so
# In some cases the .so may not be available, for example when building against musl (static linking)
if [ -f target/release/libwasmer_c_api.so ]; then \
cp target/release/libwasmer_c_api.so package/lib/libwasmer.so ;\
fi;
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
endif
endif
Expand Down
3 changes: 2 additions & 1 deletion examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(any(
windows,
// We don't support yet crosscompilation in macOS with Apple Silicon
all(target_os = "macos", target_arch = "aarch64")
all(target_os = "macos", target_arch = "aarch64"),
target_env = "musl",
)))]
fn test_cross_compilation() -> Result<(), Box<dyn std::error::Error>> {
main()
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(any(windows, target_arch = "aarch64")))]
#[cfg(not(any(windows, target_arch = "aarch64", target_env = "musl")))]
fn test_engine_headless() -> Result<(), Box<dyn std::error::Error>> {
main()
}
2 changes: 1 addition & 1 deletion examples/engine_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

#[test]
#[cfg(not(target_arch = "aarch64"))]
#[cfg(not(any(target_arch = "aarch64", target_env = "musl")))]
fn test_engine_native() -> Result<(), Box<dyn std::error::Error>> {
main()
}
8 changes: 7 additions & 1 deletion tests/compilers/traps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn test_trap_return() -> Result<()> {
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -130,6 +131,7 @@ fn test_trap_trace_cb() -> Result<()> {
feature = "test-singlepass",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -169,6 +171,7 @@ fn test_trap_stack_overflow() -> Result<()> {
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -210,6 +213,7 @@ RuntimeError: unreachable
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -424,7 +428,8 @@ fn mismatched_arguments() -> Result<()> {
feature = "test-singlepass",
feature = "test-llvm",
feature = "test-native",
all(target_os = "macos", target_arch = "aarch64")
all(target_os = "macos", target_arch = "aarch64"),
target_env = "musl",
),
ignore
)]
Expand Down Expand Up @@ -464,6 +469,7 @@ RuntimeError: indirect call type mismatch
feature = "test-llvm",
feature = "test-native",
target_arch = "aarch64",
target_env = "musl",
),
ignore
)]
Expand Down

0 comments on commit 5962d3f

Please sign in to comment.