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

chore: Build Wasmer on musl #2003

Merged
merged 1 commit into from
Mar 5, 2021
Merged

chore: Build Wasmer on musl #2003

merged 1 commit into from
Mar 5, 2021

Conversation

jubianchi
Copy link
Contributor

This patch adds a specific build for musl. Currently, it will only support JIT engine.

I also changes the workflow definition a bit so we don't depend on the OS name but rather on the environment ID which is our convention.

Closes #1482
Closes #1766

Description

Review

  • Add a short description of the the change to the CHANGELOG.md file

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 11, 2021
@bors
Copy link
Contributor

bors bot commented Jan 11, 2021

try

Build failed:

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 11, 2021
@bors
Copy link
Contributor

bors bot commented Jan 11, 2021

try

Build failed:

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 11, 2021
@bors
Copy link
Contributor

bors bot commented Jan 11, 2021

try

Timed out.

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 12, 2021
@jubianchi
Copy link
Contributor Author

bors try

@bors
Copy link
Contributor

bors bot commented Jan 12, 2021

try

Already running a review

@jubianchi
Copy link
Contributor Author

bors try-

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 12, 2021
@bors
Copy link
Contributor

bors bot commented Jan 12, 2021

try

Build failed:

@jubianchi
Copy link
Contributor Author

bors try-

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 12, 2021
@bors
Copy link
Contributor

bors bot commented Jan 12, 2021

try

Build failed:

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Jan 12, 2021
@jubianchi jubianchi force-pushed the musl-build branch 2 times, most recently from dea45a5 to ce154a2 Compare February 13, 2021 17:56
@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Feb 13, 2021
.cargo/config.toml Outdated Show resolved Hide resolved
.github/workflows/main.yaml Outdated Show resolved Hide resolved
.github/workflows/main.yaml Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@@ -1,6 +1,11 @@
# ignore wasm-c-api binaries
wasm-c-api-*
test-*
wasm-c-api/example/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change related to musl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope.

It can be extracted to a dedicated PR if needed.

@jubianchi
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Feb 19, 2021
bors bot added a commit that referenced this pull request Feb 22, 2021
2133: fix: Use space-indent when calling functions outside of rules r=Hywan a=jubianchi

This should fix failures in:
* https://github.com/wasmerio/wasmer-nightly/pull/14/checks?check_run_id=1938612785
* https://github.com/wasmerio/wasmer-nightly/pull/13/checks?check_run_id=1938633577

This will unblock #2003

Co-authored-by: jubianchi <[email protected]>
Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The asset upload duplication must be fixed, but apart from that, I'm approving this PR. Good job!

.github/workflows/main.yaml Outdated Show resolved Hide resolved
Comment on lines -619 to +657
ifeq ($(IS_WINDOWS), 1)
cp target/release/wasmer_c_api.dll package/lib/wasmer.dll
cp target/release/wasmer_c_api.lib package/lib/wasmer.lib
else
ifeq ($(IS_DARWIN), 1)

# Windows
if [ -f $(TARGET_DIR)/wasmer_c_api.dll ]; then \
cp $(TARGET_DIR)/wasmer_c_api.dll package/lib/wasmer.dll ;\
fi
if [ -f $(TARGET_DIR)/wasmer_c_api.lib ]; then \
cp $(TARGET_DIR)/wasmer_c_api.lib package/lib/wasmer.lib ;\
fi

# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
rm -f package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
# Fix the rpath for the dylib
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
else
# 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
if [ -f $(TARGET_DIR)/libwasmer_c_api.dylib ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
fi

if [ -f $(TARGET_DIR)/libwasmer_c_api.so ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.so package/lib/libwasmer.so ;\
fi
if [ -f $(TARGET_DIR)/libwasmer_c_api.a ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.a package/lib/libwasmer.a ;\
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this new approach. It's more “error-proof”.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually just about to comment that I think it's more error prone as we'll silently fail if we're missing any of these files and will just have to wait until a user reports or we notice that we didn't release one of the files we intended to.

Ideally our packaging logic would be tested and not live in our CI file. We've lost a ton of things done in CI over time from all the CI migrations we've done -- I wouldn't put anything too critical there

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think the above code is better though, but we do need tests for our packaging logic and the change above makes the need for tests greater.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkMcCaskey the problem with our previous strategy here was we relied on the host OS to define the files to copy.

This is not always the right thing to do, for example when we cross-compile this is why I changed that. Also, our strategy was not adaptative: if a user decides to change his build configuration (for example move from cdylib to staticlib) he'll have to change the Makefile. With this change, everything will automatically work.

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense, my one concern is just that it's less specific. Rather than encoding an expected state of the world "given condition X, we must have files Y, Z, ..." we just take whatever is there. So any bug that affects the files we produce will now go unnoticed. Put another way, the new code is less brittle and picky, but it's so non-brittle and picky that it won't complain if things are broken, where the old code would.

I think the real fix is to just have actual testing for our release process but I think that's out of scope for this PR.

Copy link
Contributor

@Hywan Hywan Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's accept the present patch, and then immediately open a new PR to test the package/ directory? We also have various scheduled tests that run basedwasmer-nightly (like in wasmer-go, wasmer-php etc.).

.github/workflows/main.yaml Show resolved Hide resolved
@@ -173,7 +172,7 @@ jobs:
- name: Test
run: |
make test
if: matrix.target != 'aarch64-apple-darwin'
if: matrix.build != 'macos-arm64'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are target and build the same here? It seems like they could be different

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

matrix.target and matrix.os are names defined by either Rust or GitHub. matrix.build is something we chosse on our side so I prefer to rely on our naming convention here.

If GitHub forces us to change the os this will not impact the workflow. Same for target (even if it's unlikely they will change)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that makes sense, I just want to check that there aren't extra semantics here. If I remember correctly, arm64 Mac used target or some other key for a very specific purpose and I think the difference might have been important because of cross-compilation or something

Copy link
Contributor Author

@jubianchi jubianchi Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarkMcCaskey yeah, to build for M1 we cross compile so we define (in the matrix) the Rust target to use and we were also using this in our conditionals.

But now, we have a problem: when GitHub will support M1 directly, we won't cross-compile anymore (we won't force the target through the matrix). Without my change, this would also require to change all the conditionals. With my change, we only update the matrix and we are done.

.github/workflows/main.yaml Show resolved Hide resolved
.github/workflows/main.yaml Show resolved Hide resolved
Comment on lines -619 to +657
ifeq ($(IS_WINDOWS), 1)
cp target/release/wasmer_c_api.dll package/lib/wasmer.dll
cp target/release/wasmer_c_api.lib package/lib/wasmer.lib
else
ifeq ($(IS_DARWIN), 1)

# Windows
if [ -f $(TARGET_DIR)/wasmer_c_api.dll ]; then \
cp $(TARGET_DIR)/wasmer_c_api.dll package/lib/wasmer.dll ;\
fi
if [ -f $(TARGET_DIR)/wasmer_c_api.lib ]; then \
cp $(TARGET_DIR)/wasmer_c_api.lib package/lib/wasmer.lib ;\
fi

# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
rm -f package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
# Fix the rpath for the dylib
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
else
# 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
if [ -f $(TARGET_DIR)/libwasmer_c_api.dylib ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
fi

if [ -f $(TARGET_DIR)/libwasmer_c_api.so ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.so package/lib/libwasmer.so ;\
fi
if [ -f $(TARGET_DIR)/libwasmer_c_api.a ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.a package/lib/libwasmer.a ;\
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually just about to comment that I think it's more error prone as we'll silently fail if we're missing any of these files and will just have to wait until a user reports or we notice that we didn't release one of the files we intended to.

Ideally our packaging logic would be tested and not live in our CI file. We've lost a ton of things done in CI over time from all the CI migrations we've done -- I wouldn't put anything too critical there

Comment on lines -619 to +657
ifeq ($(IS_WINDOWS), 1)
cp target/release/wasmer_c_api.dll package/lib/wasmer.dll
cp target/release/wasmer_c_api.lib package/lib/wasmer.lib
else
ifeq ($(IS_DARWIN), 1)

# Windows
if [ -f $(TARGET_DIR)/wasmer_c_api.dll ]; then \
cp $(TARGET_DIR)/wasmer_c_api.dll package/lib/wasmer.dll ;\
fi
if [ -f $(TARGET_DIR)/wasmer_c_api.lib ]; then \
cp $(TARGET_DIR)/wasmer_c_api.lib package/lib/wasmer.lib ;\
fi

# For some reason in macOS arm64 there are issues if we copy constantly in the install_name_tool util
rm -f package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.dylib package/lib/libwasmer.dylib
cp target/release/libwasmer_c_api.a package/lib/libwasmer.a
# Fix the rpath for the dylib
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib
else
# 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
if [ -f $(TARGET_DIR)/libwasmer_c_api.dylib ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.dylib package/lib/libwasmer.dylib ;\
install_name_tool -id "@rpath/libwasmer.dylib" package/lib/libwasmer.dylib ;\
fi

if [ -f $(TARGET_DIR)/libwasmer_c_api.so ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.so package/lib/libwasmer.so ;\
fi
if [ -f $(TARGET_DIR)/libwasmer_c_api.a ]; then \
cp $(TARGET_DIR)/libwasmer_c_api.a package/lib/libwasmer.a ;\
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think the above code is better though, but we do need tests for our packaging logic and the change above makes the need for tests greater.

jubianchi added a commit to wasmerio/wasmer-nightly that referenced this pull request Feb 22, 2021
jubianchi added a commit to wasmerio/wasmer-nightly that referenced this pull request Feb 22, 2021
jubianchi added a commit to wasmerio/wasmer-nightly that referenced this pull request Feb 22, 2021
chore: Update workflow to reflect what we have in wasmerio/wasmer#2003
@jubianchi
Copy link
Contributor Author

bors r+

@bors bors bot merged commit ea4ea47 into master Mar 5, 2021
@bors bors bot deleted the musl-build branch March 5, 2021 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

alpine build error Compatibility with Alpine Linux
6 participants