How to build custom rustc with wasm32-unknown-unknown target

Hi, I googled a lot but didn't find any answer. Also I asked in discord community, also no response. Here I saw a similar topic, without response. Why so? No body knows how to compile custom-rustc with wasm32-unknown-unknown support?

I am trying to build rust from source (I need to change a little in wasm32 target). I do build with command:

./x.py b --host x86_64-unknow-linux-gnu --target wasm32-unknown-unknown library/std  --stage 1

It works fine, then I add new toolchain with rustup:

rustup toolchain link stage1 build/x86_64-unknow-linux-gnu/stage1

It works fine

Then I try build simple wasm32-unknown-unknown project, but it always fail with error:

error[E0463]: can't find crate for `core`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.

I also tried to add wasm32-unknown-unknown as described in topic above with same results as in topic.

So, how do you build rustc with custom wasm32-unknown-unknown target?

When I build with above command, the ouput is:

./x.py b --host x86_64-unknow-linux-gnu --target wasm32-unknown-unknown library/std --stage 1
Updating only changed submodules
Submodules updated in 0.14 seconds
    Finished dev [unoptimized] target(s) in 0.83s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.14s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling cfg-if v0.1.10
   Compiling lazy_static v1.4.0
   Compiling cfg-if v1.0.0
   Compiling scopeguard v1.1.0
   Compiling smallvec v1.7.0
   Compiling hashbrown v0.11.0
   Compiling instant v0.1.6
   Compiling ppv-lite86 v0.2.8
   Compiling pin-project-lite v0.2.4
   Compiling rustc-hash v1.1.0
   Compiling either v1.6.0
   Compiling remove_dir_all v0.5.3
   Compiling arrayvec v0.7.0
   Compiling opaque-debug v0.3.0
   Compiling stable_deref_trait v1.2.0
   Compiling cpuid-bool v0.1.2
   Compiling unicode-width v0.1.8
   Compiling scoped-tls v1.0.0
   Compiling unicode-xid v0.2.2
   Compiling termcolor v1.1.2
   Compiling annotate-snippets v0.8.0
   Compiling datafrog v2.0.1
   Compiling tinyvec v0.3.4
   Compiling regex-syntax v0.6.25
   Compiling itoa v0.4.6
   Compiling ansi_term v0.12.1
   Compiling unicode-script v0.5.3
   Compiling fixedbitset v0.2.0
   Compiling if_chain v1.0.0
   Compiling rustc-demangle v0.1.21
   Compiling punycode v0.4.1
   Compiling pathdiff v0.2.0
   Compiling cc v1.0.69
   Compiling odht v0.3.1
   Compiling lock_api v0.4.1
   Compiling tracing-core v0.1.21
   Compiling sharded-slab v0.1.1
   Compiling thread_local v1.0.1
   Compiling itertools v0.9.0
   Compiling getopts v0.2.21
   Compiling rustc_lexer v0.1.0 (/home/caiiiycuk/rust/rust/compiler/rustc_lexer)
   Compiling unicode-normalization v0.1.13
   Compiling libc v0.2.106
   Compiling regex-automata v0.1.10
   Compiling log v0.4.14
   Compiling maybe-uninit v2.0.0
   Compiling bitflags v1.2.1
   Compiling typenum v1.12.0
   Compiling memchr v2.4.1
   Compiling ryu v1.0.5
   Compiling snap v1.0.1
   Compiling crc32fast v1.2.0
   Compiling indexmap v1.7.0
   Compiling crossbeam-utils v0.7.2
   Compiling memoffset v0.5.5
   Compiling num-traits v0.2.12
   Compiling unicode-security v0.0.5
   Compiling parking_lot_core v0.8.3
   Compiling getrandom v0.2.0
   Compiling num_cpus v1.13.0
   Compiling memmap2 v0.2.1
   Compiling perf-event-open-sys v1.0.1
   Compiling jobserver v0.1.24
   Compiling atty v0.2.14
   Compiling termize v0.1.1
   Compiling getrandom v0.1.14
   Compiling ena v0.14.0
   Compiling polonius-engine v0.13.0
   Compiling tracing-log v0.1.2
   Compiling psm v0.1.16
   Compiling rustc_apfloat v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_apfloat)
   Compiling matchers v0.0.1
   Compiling aho-corasick v0.7.18
   Compiling generic-array v0.14.4
   Compiling rustc_llvm v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_llvm)
   Compiling crossbeam-queue v0.2.3
   Compiling rustc_serialize v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_serialize)
   Compiling petgraph v0.5.1
   Compiling object v0.26.2
   Compiling crossbeam-epoch v0.8.2
   Compiling num-integer v0.1.43
   Compiling parking_lot v0.11.1
   Compiling rand_core v0.6.2
   Compiling rand_core v0.5.1
   Compiling stacker v0.1.14
   Compiling digest v0.9.0
   Compiling block-buffer v0.9.0
   Compiling regex v1.5.4
   Compiling crossbeam-deque v0.7.4
   Compiling chrono v0.4.19
   Compiling measureme v10.0.0
   Compiling rand_chacha v0.3.0
   Compiling rand_xoshiro v0.6.0
   Compiling rand_chacha v0.2.2
   Compiling sha2 v0.9.1
   Compiling md-5 v0.9.1
   Compiling sha-1 v0.9.1
   Compiling rustc-rayon-core v0.3.1
   Compiling rand v0.8.4
   Compiling rand v0.7.3
   Compiling tracing v0.1.28
   Compiling serde v1.0.125
   Compiling rustc-rayon v0.3.1
   Compiling tempfile v3.2.0
   Compiling rustc_index v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_index)
   Compiling chalk-ir v0.55.0
   Compiling rustc_data_structures v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_data_structures)
   Compiling gsgdt v0.1.2
   Compiling serde_json v1.0.59
   Compiling tracing-serde v0.1.2
   Compiling rls-span v0.5.3
   Compiling rustc_arena v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_arena)
   Compiling rustc_type_ir v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_type_ir)
   Compiling tracing-subscriber v0.2.16
   Compiling rls-data v0.19.1
   Compiling rustc_span v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_span)
   Compiling tracing-tree v0.1.9
   Compiling chalk-solve v0.55.0
   Compiling rustc_ast v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_ast)
   Compiling rustc_target v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_target)
   Compiling rustc_feature v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_feature)
   Compiling rustc_parse_format v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_parse_format)
   Compiling chalk-engine v0.55.0
   Compiling rustc_ast_pretty v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_ast_pretty)
   Compiling rustc_lint_defs v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_lint_defs)
   Compiling rustc_hir v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_hir)
   Compiling rustc_errors v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_errors)
   Compiling rustc_hir_pretty v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_hir_pretty)
   Compiling rustc_session v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_session)
   Compiling rustc_attr v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_attr)
   Compiling rustc_query_system v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_query_system)
   Compiling rustc_parse v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_parse)
   Compiling rustc_middle v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_middle)
   Compiling rustc_ast_lowering v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_ast_lowering)
   Compiling rustc_ast_passes v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_ast_passes)
   Compiling rustc_expand v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_expand)
   Compiling rustc_infer v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_infer)
   Compiling rustc_mir_dataflow v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_mir_dataflow)
   Compiling rustc_incremental v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_incremental)
   Compiling rustc_symbol_mangling v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_symbol_mangling)
   Compiling rustc_query_impl v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_query_impl)
   Compiling rustc_passes v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_passes)
   Compiling rustc_monomorphize v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_monomorphize)
   Compiling rustc_save_analysis v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_save_analysis)
   Compiling rustc_metadata v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_metadata)
   Compiling rustc_builtin_macros v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_builtin_macros)
   Compiling rustc_trait_selection v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_trait_selection)
   Compiling rustc_codegen_ssa v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_codegen_ssa)
   Compiling rustc_resolve v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_resolve)
   Compiling rustc_lint v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_lint)
   Compiling rustc_const_eval v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_const_eval)
   Compiling rustc_ty_utils v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_ty_utils)
   Compiling rustc_traits v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_traits)
   Compiling rustc_mir_build v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_mir_build)
   Compiling rustc_codegen_llvm v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_codegen_llvm)
   Compiling rustc_plugin_impl v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_plugin_impl)
   Compiling rustc_mir_transform v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_mir_transform)
   Compiling rustc_typeck v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_typeck)
   Compiling rustc_borrowck v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_borrowck)
   Compiling rustc_privacy v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_privacy)
   Compiling rustc_interface v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_interface)
   Compiling rustc_driver v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc_driver)
   Compiling rustc-main v0.0.0 (/home/caiiiycuk/rust/rust/compiler/rustc)
    Finished release [optimized] target(s) in 16m 43s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> wasm32-unknown-unknown)
   Compiling cc v1.0.69
   Compiling core v0.0.0 (/home/caiiiycuk/rust/rust/library/core)
   Compiling libc v0.2.106
   Compiling memchr v2.4.1
   Compiling dlmalloc v0.2.1
   Compiling std v0.0.0 (/home/caiiiycuk/rust/rust/library/std)
   Compiling compiler_builtins v0.1.49
   Compiling unwind v0.0.0 (/home/caiiiycuk/rust/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/home/caiiiycuk/rust/rust/library/rustc-std-workspace-core)
   Compiling alloc v0.0.0 (/home/caiiiycuk/rust/rust/library/alloc)
   Compiling cfg-if v0.1.10
   Compiling adler v0.2.3
   Compiling rustc-demangle v0.1.21
   Compiling rustc-std-workspace-alloc v1.99.0 (/home/caiiiycuk/rust/rust/library/rustc-std-workspace-alloc)
   Compiling panic_unwind v0.0.0 (/home/caiiiycuk/rust/rust/library/panic_unwind)
   Compiling panic_abort v0.0.0 (/home/caiiiycuk/rust/rust/library/panic_abort)
   Compiling gimli v0.25.0
   Compiling miniz_oxide v0.4.0
   Compiling object v0.26.2
   Compiling std_detect v0.1.5 (/home/caiiiycuk/rust/rust/library/stdarch/crates/std_detect)
   Compiling hashbrown v0.11.0
   Compiling addr2line v0.16.0
warning: dropping unsupported crate type `dylib` for target `wasm32-unknown-unknown`

warning: `std` (lib) generated 1 warning
   Compiling rustc-std-workspace-std v1.99.0 (/home/caiiiycuk/rust/rust/library/rustc-std-workspace-std)
   Compiling proc_macro v0.0.0 (/home/caiiiycuk/rust/rust/library/proc_macro)
   Compiling unicode-width v0.1.8
   Compiling getopts v0.2.21
   Compiling test v0.0.0 (/home/caiiiycuk/rust/rust/library/test)
warning: `test` (lib) generated 1 warning (1 duplicate)
    Finished release [optimized] target(s) in 41.69s
Copying stage1 std from stage1 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / wasm32-unknown-unknown)
Build completed successfully in 0:17:27

Is Compiling core v0.0.0 (/home/caiiiycuk/rust/rust/library/core) means that crate core is compiled?

You need to use --target x86_64-unknown-linux-gnu --target wasm32-unknown-unknown". If you don't include the host in --target you can't build build scripts and proc macros that need to be compiled for the host.

Edit: corrected necessary arguments.

Thank you very much. That works!

Have another minor issue, when I compile test project it fail because can't find rust-lld in stage1. It's strange because I compile everything for --stage 1... I workaround this by copying rust-lld from stage0.

With this workaround everything works!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.