Page MenuHomeFreeBSD

lang/rust: add WEBASM (WebAssembly) option
ClosedPublic

Authored by mikael on Wed, Feb 12, 6:04 PM.

Details

Reviewers
tobik
Group Reviewers
rust
Commits
rP526265: lang/rust: add the WASM option
Summary

This patch adds the WASM option to build the wasm32-unknown-unknown target, off by default.
web assembly seems popular nowadays and people tries to use it on FreeBSD without success: https://github.com/rust-lang/rustup/issues/1843

I haven't found a better way to transform, say, wasm32-unknown-unknown aarch64-unknown-freebsd to ["wasm32-unknown-unknown","aarch64-unknown-freebsd"]

I would also like to discuss the possibility to have this option enabled by default, it only adds 18MB of disk space (or we can wait for subpackage)

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

mikael created this revision.Wed, Feb 12, 6:04 PM
tobik added a comment.Wed, Feb 12, 6:41 PM

I would also like to discuss the possibility to have this option enabled by default, it only adds 18MB of disk space

How much longer will the build be? It's already quite long...

lang/rust/Makefile
92–101 ↗(On Diff #68210)
_RUST_TARGETS=  "${_RUST_TARGET}"
.if ${PORT_OPTIONS:MWASM}
_RUST_TARGETS+= "wasm32-unknown-unknown"
.endif
RUST_TARGETS=   [${_RUST_TARGETS:ts,}]

But none of that is needed. See below.

165 ↗(On Diff #68210)

Instead of RUST_TARGETS just add

.if ${PORT_OPTIONS:MWASM}
	@${ECHO_CMD} 'target=["${_RUST_TARGET}","wasm32-unknown-unknown"]' >> ${WRKSRC}/config.toml
.endif

Remove spaces around =.

173 ↗(On Diff #68210)

Why do we need to build the bundled lld?

Remove spaces around =.

tobik added a reviewer: rust.Wed, Feb 12, 6:43 PM
mikael updated this revision to Diff 68217.Wed, Feb 12, 7:39 PM

address comments

mikael added inline comments.Wed, Feb 12, 7:44 PM
lang/rust/Makefile
173 ↗(On Diff #68210)

by default rust uses rust-lld as a linker (I think I was able to use lld from devel/llvm with this invocation "env RUSTFLAGS='-C linker=wasm-ld90'"), it'll be easier for newcomer to not have to search the web for a solution to this error message (as seen in https://github.com/rust-lang/rustup/issues/1843):

error: linker `rust-lld` not found
  |
  = note: No such file or directory (os error 2)

The option will install /usr/local/lib/rustlib/x86_64-unknown-freebsd/bin/rust-lld and rust will manage to pick this linker automatically

I would also like to discuss the possibility to have this option enabled by default, it only adds 18MB of disk space

How much longer will the build be? It's already quite long...

On my ryzen 3900x:
build time: 00:19:47
build time: 00:22:07 (with wasm)

Or we can download upstream version at https://static.rust-lang.org/dist/rust-std-1.33.0-wasm32-unknown-unknown.tar.gz (with the current version instead of 1.33.0), idk.

I think I was able to use lld from devel/llvm with this invocation

I've been using that for embedded (thumbv6m, thumbv7em) as well. Having rust-lld is silly when we have LLD in llvmXX packages. Maybe rustc should auto detect our LLDs..

tobik accepted this revision.Sat, Feb 15, 1:52 PM
tobik added a subscriber: manu.

Build time increase seems to be in an acceptable margin. Feel free to commit it after your mentor @manu approves and if lang/rust-nightly also builds with it.

Let's only enable WASM (and SOURCES) by default during the Rust 1.42.0 update.

lang/rust/Makefile
173 ↗(On Diff #68210)

Ok. Only FTR, Rust could probably be patched to use wasm-ld90 or similar in src/librustc_target/spec/wasm32_base.rs.

This revision is now accepted and ready to land.Sat, Feb 15, 1:53 PM
manu added a comment.Sat, Feb 15, 2:04 PM

Approved-by: manu (mentor)

This revision was automatically updated to reflect the committed changes.