diff --git a/default.nix b/default.nix index f239804fb4c..b25d8a6e325 100644 --- a/default.nix +++ b/default.nix @@ -18,17 +18,83 @@ let ic-ref = ic-ref-pkgs.ic-ref; in let haskellPackages = nixpkgs.haskellPackages.override { overrides = import nix/haskell-packages.nix nixpkgs subpath; }; in + +let + rustc-custom = stdenv.mkDerivation rec { + name = "rustc-custom"; + rev = "e327a823d8b64e294e490efeca7829f383aa119d"; + src = nixpkgs.fetchgit { + url = "https://github.com/rust-lang/rust"; + rev = "e327a823d8b64e294e490efeca7829f383aa119d"; + sha256 = "1jw64zdf0ikvgnxn72rpbl548s5wzgbc47sx920944872651b7bl"; + }; + + buildInputs = [ + nixpkgs.llvm_10 + nixpkgs.python3 + nixpkgs.curl + nixpkgs.cacert + nixpkgs.cmake + nixpkgs.ninja + nixpkgs.libxml2 + nixpkgs.openssl + nixpkgs.pkgconfig + # https://github.com/sfackler/rust-openssl/issues/948 + nixpkgs.libiconv + ]; + + configurePhase = '' + echo -n "Using llvm-config version " + ${nixpkgs.llvm_10}/bin/llvm-config --version + + { + echo 'changelog-seen = 2' + + echo '[build]' + echo 'extended = true' + echo 'tools = ["cargo", "src"]' + + echo '[target.x86_64-unknown-linux-gnu]' + echo 'llvm-config = "${nixpkgs.llvm_10}/bin/llvm-config"' + + echo '[install]' + echo "prefix = \"$out\"" + echo "sysconfdir = \"$out/etc\"" + } > config.toml + + echo "config.toml contents:" + echo "-------------------------------------------------------------------" + cat config.toml + echo "-------------------------------------------------------------------" + ''; + + buildPhase = '' + mkdir home + export HOME=$PWD/home + patchShebangs . + ./x.py build + ''; + + installPhase = '' + ./x.py install + ''; + }; +in + let - rtsBuildInputs = with nixpkgs; [ - clang_10 # for native/wasm building - lld_10 # for wasm building - llvmPackages_10.bintools - rustc-nightly - cargo-nightly - xargo - wasmtime - rust-bindgen - rustfmt + rtsBuildInputs = [ + nixpkgs.clang_10 # for native/wasm building + nixpkgs.lld_10 # for wasm building + nixpkgs.llvmPackages_10.bintools + nixpkgs.wasmtime + nixpkgs.rust-bindgen + + rustc-custom + + # For some reason we can't build rustfmt component in the rustc-custom + # derivation above (probably a bug in the Rust repo) so we use the one from + # nixpkgs + nixpkgs.rustfmt ]; llvmEnv = '' @@ -152,7 +218,6 @@ rec { buildInputs = rtsBuildInputs; preBuild = '' - export XARGO_HOME=$PWD/xargo-home export CARGO_HOME=$PWD/cargo-home # this replicates logic from nixpkgs’ pkgs/build-support/rust/default.nix @@ -414,7 +479,6 @@ rec { inherit (nixpkgs) wabt wasmtime wasm; filecheck = nixpkgs.linkFarm "FileCheck" [ { name = "bin/FileCheck"; path = "${nixpkgs.llvm}/bin/FileCheck";} ]; - inherit (nixpkgs) xargo; # gitMinimal is used by nix/gitSource.nix; building it here warms the nix cache inherit (nixpkgs) gitMinimal; diff --git a/nix/default.nix b/nix/default.nix index 8c8d204d065..309de0c6520 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -57,7 +57,6 @@ let rustc = rustc-nightly; cargo = cargo-nightly; }; - xargo = self.callPackage ./xargo.nix {}; }) # wasm-profiler diff --git a/nix/xargo.nix b/nix/xargo.nix deleted file mode 100644 index 16e149ae2b0..00000000000 --- a/nix/xargo.nix +++ /dev/null @@ -1,36 +0,0 @@ -# xargo is used to build motoko-rts for wasm32. We need to make a shared Wasm -# library for the RTS (that's what moc-ld supports) but Rust ships wasm32 -# libraries (core and std) without PIC relocation model, so we use xargo to make -# PIC versions of core and std. - -{ rustPlatform-nightly, fetchFromGitHub, lib, python, cmake, llvmPackages, clang, stdenv, darwin, zlib }: - -rustPlatform-nightly.buildRustPackage rec { - name = "xargo"; - - src = fetchFromGitHub { - owner = "japaric"; - repo = "${name}"; - rev = "16035a7c401262824edcb87e1401fe4b05a5ccc0"; - sha256 = "0m1dg7vwmmlpqp20p219gsm7zbnnii6lik6hc2vvfsdmnygf271l"; - fetchSubmodules = true; - }; - - cargoSha256 = "171a7xm47qdcdd6n67plyvnsxp00hn6skx5vzxd8a2kmblfqn5gy"; - - doCheck = false; - USER = "nobody"; # for xargo tests (if we would run them) - - meta = with lib; { - description = "The sysroot manager that lets you build and customize std"; - homepage = "https://github.com/japaric/xargo"; - license = licenses.mit; - maintainers = [ { - email = "omer.agacan@dfinity.org"; - github = "osa1"; - githubId = 123123; - name = "Ömer Sinan Ağacan"; - } ]; - platforms = platforms.unix; - }; -} diff --git a/rts/Makefile b/rts/Makefile index 9eb0162dfe1..6f25640a486 100644 --- a/rts/Makefile +++ b/rts/Makefile @@ -201,11 +201,11 @@ $(TOMMATH_BINDINGS_RS): | _build $(RTS_RUST_WASM_A): $(TOMMATH_BINDINGS_RS) $(wildcard motoko-rts/src/*.rs) | _build/wasm - cd motoko-rts && xargo build --release --target=wasm32-unknown-emscripten + cd motoko-rts && cargo build --release --target=wasm32-unknown-emscripten -Z build-std=core cp motoko-rts/target/wasm32-unknown-emscripten/release/libmotoko_rts.a $@ $(RTS_RUST_DEBUG_WASM_A): $(TOMMATH_BINDINGS_RS) $(wildcard motoko-rts/src/*.rs) | _build/wasm - cd motoko-rts && xargo build --target=wasm32-unknown-emscripten + cd motoko-rts && cargo build --target=wasm32-unknown-emscripten -Z build-std=core cp motoko-rts/target/wasm32-unknown-emscripten/debug/libmotoko_rts.a $@ # @@ -214,7 +214,7 @@ $(RTS_RUST_DEBUG_WASM_A): $(TOMMATH_BINDINGS_RS) $(wildcard motoko-rts/src/*.rs) .PHONY: test test: $(TOMMATH_WASM_A) $(TOMMATH_BINDINGS_RS) - cd motoko-rts-tests && cargo build --target=wasm32-wasi + cd motoko-rts-tests && cargo build --target=wasm32-wasi -Z build-std=core wasmtime --disable-cache --cranelift motoko-rts-tests/target/wasm32-wasi/debug/motoko-rts-tests.wasm # @@ -259,5 +259,4 @@ clean: mo-rts-debug.wasm \ motoko-rts/target \ motoko-rts-tests/target \ - motoko-rts/xargo-home \ motoko-rts/cargo-home diff --git a/rts/README.md b/rts/README.md index d6fbe601eaf..d0a6e99c222 100644 --- a/rts/README.md +++ b/rts/README.md @@ -58,7 +58,7 @@ See `motoko-rts/src/bigint.rs` for the technical details. Rust build ---------- -The Rust parts are built from `motoko-rts`, using `xargo` and `cargo`. +The Rust parts are built from `motoko-rts`, using `cargo`. To build this in nix, we need pre-fetch some dependencies (currently `compiler_builtins` and `libc`). This works in `nix-build` by: diff --git a/rts/motoko-rts/Cargo.lock b/rts/motoko-rts/Cargo.lock index c076980202a..9a4977eb130 100644 --- a/rts/motoko-rts/Cargo.lock +++ b/rts/motoko-rts/Cargo.lock @@ -1,10 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "compiler_builtins" -version = "0.1.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3748f82c7d366a0b4950257d19db685d4958d2fa27c6d164a3f069fec42b748b" +version = 3 [[package]] name = "libc" @@ -16,6 +12,5 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" name = "motoko-rts" version = "0.1.0" dependencies = [ - "compiler_builtins", "libc", ] diff --git a/rts/motoko-rts/Cargo.toml b/rts/motoko-rts/Cargo.toml index 0b39bd7945d..e56148590d8 100644 --- a/rts/motoko-rts/Cargo.toml +++ b/rts/motoko-rts/Cargo.toml @@ -22,20 +22,6 @@ panic_handler = [] [dependencies] libc = { version = "0.2.81", default_features = false } -# Added here so that it ends up in Cargo.lock, so that nix will pre-fetch it -[dependencies.compiler_builtins] -version = "0.1.39" -# Without this feature we get dozens of duplicate symbol errors when generating -# the final shared .wasm file: -# -# wasm-ld: error: duplicate symbol: __multi3 -# >>> defined in _build/wasm/libmotoko_rts.a(compiler_builtins-d709bd899857aa61.compiler_builtins.3abndchk-cgu.0.rcgu.o) -# >>> defined in _build/wasm/libmotoko_rts.a(compiler_builtins-06d1ead628e1f468.compiler_builtins.6moz1ltd-cgu.0.rcgu.o) -# -# It seems like we're linking multiple versions of compiler_builtins in the same -# shared library, which we should fix at some point. TODO -features = ["mangled-names"] - [profile.dev] panic = "abort" diff --git a/rts/motoko-rts/Xargo.toml b/rts/motoko-rts/Xargo.toml deleted file mode 100644 index d3910abede1..00000000000 --- a/rts/motoko-rts/Xargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[dependencies.core] -stage = 0 - -[dependencies.compiler_builtins] -stage = 1 -version = "0.1.39" diff --git a/rts/motoko-rts/native/Cargo.toml b/rts/motoko-rts/native/Cargo.toml index a25a85d332f..426fbecdc9f 100644 --- a/rts/motoko-rts/native/Cargo.toml +++ b/rts/motoko-rts/native/Cargo.toml @@ -11,10 +11,6 @@ path = "../src/lib.rs" [dependencies] libc = { version = "0.2.73", default_features = false } -[dependencies.compiler_builtins] -version = "0.1.39" -features = ["mangled-names"] - [profile.dev] panic = "abort"