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 cargo's build-std instead of xargo #2251

Closed
osa1 opened this issue Jan 12, 2021 · 1 comment
Closed

Use cargo's build-std instead of xargo #2251

osa1 opened this issue Jan 12, 2021 · 1 comment
Labels
compiler Motoko → Wasm P2 medium priority, resolve within a couple of milestones

Comments

@osa1
Copy link
Contributor

osa1 commented Jan 12, 2021

Apparently cargo recently gained the ability to build Rust's standard library: https://doc.rust-lang.org/cargo/reference/unstable.html#build-std this command replaces xargo.

I just tried this locally, it's just a matter of updating rustc and cargo:

diff --git a/nix/default.nix b/nix/default.nix
index 7588024a..4f33d260 100644
--- a/nix/default.nix
+++ b/nix/default.nix
@@ -41,7 +41,7 @@ let
         # Rust nightly
         (self: super: let
           moz_overlay = import self.sources.nixpkgs-mozilla self super;
-          rust-channel = moz_overlay.rustChannelOf { date = "2020-07-22"; channel = "nightly"; };
+          rust-channel = moz_overlay.rustChannelOf { date = "2020-12-29"; channel = "nightly"; };
         in rec {
           rustc-nightly = rust-channel.rust.override {
             targets = [ "wasm32-unknown-unknown" "wasm32-unknown-emscripten" ];

and updating the Makefile:

diff --git a/rts/Makefile b/rts/Makefile
index c23f3fdf..7d980bbd 100644
--- a/rts/Makefile
+++ b/rts/Makefile
@@ -164,7 +164,7 @@ _build/wasm/libmotoko_rts.a: | _build/wasm
        # NB. codegen-units=1 is to make debugging easier, not strictly
        # necessary
        cd motoko-rts && \
-           xargo -v rustc --target=wasm32-unknown-emscripten --release -- \
+           cargo -v rustc -Zbuild-std=core --target=wasm32-unknown-emscripten --release -- \
                -Crelocation-model=pic -Ccodegen-units=1
        cp motoko-rts/target/wasm32-unknown-emscripten/release/libmotoko_rts.a $@

However I couldn't make this work in nix-shell and nix-build. There's always some dependency issue, and other errors that I don't understand.

When I try locally outside of nix-shell I can build the release RTS and link it, but the final linker command fails when producing debug RTS:

wasm-ld -o mo-rts-debug.wasm \
        --import-memory --shared --no-entry --gc-sections \
        --export=__wasm_call_ctors \
        --export=memcpy \
        --export=memcmp \
        --whole-archive \
        _build/wasm/libmotoko_rts_debug.a _build/wasm/rts_debug.o ...
wasm-ld: error: motoko_rts-a73c3d27a1126524.3lq75tfopvybv06x.rcgu.o: Bad relocation type:
make: *** [Makefile:200: mo-rts-debug.wasm] Error 1

I don't know if this is a cargo/rustc bug or me using the command incorrectly.

@rossberg rossberg added compiler Motoko → Wasm P2 medium priority, resolve within a couple of milestones labels Feb 2, 2021
@osa1
Copy link
Contributor Author

osa1 commented Nov 10, 2021

This is implemented with #2761, closing.

@osa1 osa1 closed this as completed Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Motoko → Wasm P2 medium priority, resolve within a couple of milestones
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants