roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
3.86k stars 284 forks source link

fix: wasi-libc.a library packaging #6834

Closed r-bar closed 1 week ago

r-bar commented 1 week ago

This PR addresses the following issues:

The net result of this PR is the roc binary in the release package is able to run the nodejs-interop/wasm example using the instructions in the README.

The release package now looks like:

$ earthly +build-nightly-release --RELEASE_FOLDER_NAME=out
$ tar tf out.tar.gz
(truncated for brevity where globs are shown)
out/
out/examples/**
out/crates/
out/crates/compiler/builtins/bitcode/*
out/crates/roc_std/**
out/roc
out/roc_language_server
out/lib/
out/lib/wasi-libc.a
out/LICENSE
out/LEGAL_DETAILS

The original issue was the roc CLI was using the WASI_LIBC_PATH to lookup the path to wasi-libc.a. When building locally this would work fine. This would end up pointing to $PROJECT_ROOT/target/$PROFILE/build/wasi_libc_sys-$BUILD_ID/wasi-libc.a. In the release package this would result in the roc binary looking for the library in the static location of /earthlybuild/... which inevitably would not exist on the end user's machine. The new logic for the wasi-libc.a lookup matches the logic for looking up zig glue where it checks in a lib folder next to the binary. This logic works for the current release format assuming the user keeps the contents of the release package together and either executes roc from the package or symlinks the roc binary into their path.

Potential followup:

There are a few points of cleanup that I think are probably good followup work, but since I am a new contributor I did not want to change too much in this initial PR.