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

Use Custom Rust Targets for Shared Wasm Libraries #4683

Merged
merged 17 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/niv-updater-rare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: knl/niv-updater-action@v13
with:
# might be too noisy
whitelist: 'ic-ref,musl-wasi,ic-wasm'
whitelist: 'ic-ref,ic-wasm'
labels: |
automerge-squash
keep_updating: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/niv-updater-trial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: niv-updater-action
uses: knl/niv-updater-action@v13
with:
whitelist: 'nixpkgs,musl-wasi,ic'
whitelist: 'nixpkgs,ic'
labels: |
autoclose
keep_updating: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/niv-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: knl/niv-updater-action@v13
with:
# might be too noisy
blacklist: 'nixpkgs,ic-ref,musl-wasi,ic'
blacklist: 'nixpkgs,ic-ref,ic'
labels: |
automerge-squash
keep_updating: true
Expand Down
70 changes: 2 additions & 68 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,63 +23,10 @@ let ic-ref-run =
let haskellPackages = nixpkgs.haskellPackages.override {
overrides = import nix/haskell-packages.nix nixpkgs subpath;
}; in
let llvm_sources = nixpkgs.fetchFromGitHub {
owner = "llvm";
repo = "llvm-project";
rev = "llvmorg-18.1.8";
sha256 = "sha256-iiZKMRo/WxJaBXct9GdAcAT3cz9d9pnAcO1mmR6oPNE=";
}; in
let patched-wasm-ld = stdenv.mkDerivation {
name = "wasm-ld";
src = llvm_sources;
nativeBuildInputs = with nixpkgs; [ cmake ninja ];
buildInputs = with nixpkgs; [ llvmPackages_18.libllvm libxml2 ];

patchPhase = ''
patch lld/wasm/Relocations.cpp << EOF
@@ -104,9 +104,15 @@ void scanRelocations(InputChunk *chunk) {
case R_WASM_TABLE_INDEX_SLEB64:
case R_WASM_TABLE_INDEX_REL_SLEB:
case R_WASM_TABLE_INDEX_REL_SLEB64:
- if (requiresGOTAccess(sym))
- break;
+ if (!sym->isDefined()) {
+ error(toString(file) + ": relocation " + relocTypeToString(reloc.Type) +
+ " cannot be used against an undefined symbol \`" + toString(*sym) +
+ "\`");
+ }
out.elemSec->addEntry(cast<FunctionSymbol>(sym));
+ if (requiresGOTAccess(sym)) {
+ addGOTEntry(sym);
+ }
break;
case R_WASM_GLOBAL_INDEX_LEB:
case R_WASM_GLOBAL_INDEX_I32:
EOF
cd lld
'';

outputs = [ "out" ];
}; in
# Selectively build llvm binary tools.
# Exclude wasm-ld, as this is patched separately.
let llvm_bintools = stdenv.mkDerivation {
name = "llvm_bintools";
src = llvm_sources;
nativeBuildInputs = with nixpkgs; [ cmake ninja python3 ];
buildInputs = with nixpkgs; [ llvmPackages_18.libllvm libxml2 ];

preConfigure = ''
cd llvm
'';

outputs = [ "out" ];
}; in
let
rtsBuildInputs = with nixpkgs; [
llvmPackages_18.clang
llvm_bintools
patched-wasm-ld
llvmPackages_18.bintools
rustc-nightly
cargo-nightly
wasmtime
Expand Down Expand Up @@ -193,15 +140,6 @@ let ocaml_exe = name: bin: rts:
$out/bin/* --help >/dev/null
'';
};

musl-wasi-sysroot = stdenv.mkDerivation {
name = "musl-wasi-sysroot";
src = nixpkgs.sources.musl-wasi;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
make SYSROOT="$out" include_dirs
'';
};
in

rec {
Expand Down Expand Up @@ -295,8 +233,6 @@ rec {

${llvmEnv}
export TOMMATHSRC=${nixpkgs.sources.libtommath}
export MUSLSRC=${nixpkgs.sources.musl-wasi}/libc-top-half/musl
export MUSL_WASI_SYSROOT=${musl-wasi-sysroot}
'';

doCheck = true;
Expand Down Expand Up @@ -383,7 +319,7 @@ rec {

# extra deps for test/ld
ldTestDeps =
with nixpkgs; [ patched-wasm-ld llvmPackages_18.clang ];
with nixpkgs; [ llvmPackages_18.lld llvmPackages_18.clang ];

testDerivation = args:
stdenv.mkDerivation (testDerivationArgs // args);
Expand Down Expand Up @@ -906,8 +842,6 @@ EOF
'';
ESM=nixpkgs.sources.esm;
TOMMATHSRC = nixpkgs.sources.libtommath;
MUSLSRC = "${nixpkgs.sources.musl-wasi}/libc-top-half/musl";
MUSL_WASI_SYSROOT = musl-wasi-sysroot;
LOCALE_ARCHIVE = nixpkgs.lib.optionalString stdenv.isLinux "${nixpkgs.glibcLocales}/lib/locale/locale-archive";
MOTOKO_BASE = base-src;
CANDID_TESTS = "${nixpkgs.sources.candid}/test";
Expand Down
4 changes: 1 addition & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let
};
};

# No testing of atdgen, as it pulls in python stuff, tricky on musl
# No testing of atdgen, as it pulls in python stuff
atdgen = super.ocamlPackages.atdgen.overrideAttrs { doCheck = false; };
};
}
Expand All @@ -95,9 +95,7 @@ let
in rec {
rustc-nightly = rust-channel.rust.override {
targets = [
"wasm32-unknown-emscripten"
"wasm32-wasi"
"i686-unknown-linux-gnu"
];
extensions = ["rust-src"];
};
Expand Down
13 changes: 0 additions & 13 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@
"url": "https://github.com/kritzcreek/motoko-matchers/archive/cb838c192df3328ff9ae172e2dc7338cf55e74bf.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"musl-wasi": {
"branch": "main",
"builtin": false,
"description": "WASI libc implementation for WebAssembly",
"homepage": "https://wasi.dev",
"owner": "WebAssembly",
"repo": "wasi-libc",
"rev": "c5264e2bbe532994d06b039005f2af91bedcc1a6",
"sha256": "1skw2jqzaidr2zbzbjw32b36xvqniwf4if8cr4kbpp8vjvh7j2lr",
"type": "tarball",
"url": "https://github.com/WebAssembly/wasi-libc/archive/c5264e2bbe532994d06b039005f2af91bedcc1a6.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "release-24.05",
"description": "Nix Packages collection & NixOS",
Expand Down
Loading
Loading