On 2022/09/07 12:22, Luca Castagnini wrote:
> Hi,
> 
> I was wondering if it would be possible to include in ports a package for 
> Rust WebAssembly.
> I made a first attempt at editing the current lang/rust/Makefile to produce 
> an extra rust-wasm32 package. I am not too expert on makefiles and probably 
> need a help to make it better.
> 
> So far the compilation seems to work under amd64 and I can compile a wasm 
> test project with
> RUSTFLAGS="-C linker=lld" cargo build --target wasm32-unknown-unknown
> 
> without the RUSTFLAGS variable I get a "rust-lld not found" error. 
> linker=cflags works also. It could probably be solved by tuning rust's 
> compilation config (under [target.wasm32-unknown-unknown]) but I haven't 
> experimented much yet, I am a beginner at rust.
> 
> wasm-pack still gives me a segmentation fault, I will look at it next.
> 
> I attach the makefile, plist and descr.
> 
> Let me know if there is interest.

I have no comment on the change itself, but for the benefit of other
porters here are the changes in the form of a diff for easier review

Index: Makefile
===================================================================
RCS file: /cvs/ports/lang/rust/Makefile,v
retrieving revision 1.149
diff -u -p -r1.149 Makefile
--- Makefile    28 Aug 2022 18:26:20 -0000      1.149
+++ Makefile    7 Sep 2022 12:06:17 -0000
@@ -10,6 +10,7 @@ COMMENT-main =                compiler for Rust Langua
 COMMENT-gdb =          Rust debugger through gdb
 COMMENT-clippy =       Rust linter
 COMMENT-rustfmt =      Rust code formatter
+COMMENT-wasm32 =       Rust toolchain for Wasm32
 
 V =                    1.63.0
 REVISION =             0
@@ -29,8 +30,9 @@ PKGNAME-main =                rust-${V}
 PKGNAME-gdb =          rust-gdb-${V}
 PKGNAME-clippy =       rust-clippy-${V}
 PKGNAME-rustfmt =      rust-rustfmt-${V}
+PKGNAME-wasm32 =       rust-wasm32-${V}
 
-MULTI_PACKAGES =       -main -gdb -clippy -rustfmt
+MULTI_PACKAGES =       -main -gdb -clippy -rustfmt -wasm32
 
 CATEGORIES =           lang
 
@@ -45,6 +47,7 @@ WANTLIB-main =                ${COMPILER_LIBCXX} c cry
 WANTLIB-gdb =
 WANTLIB-clippy =       ${COMPILER_LIBCXX} c m pthread
 WANTLIB-rustfmt =      ${COMPILER_LIBCXX} c m pthread
+WANTLIB-wasm32 =
 
 MASTER_SITES =         https://static.rust-lang.org/dist/ \
                        https://dev-static.rust-lang.org/dist/
@@ -114,6 +117,8 @@ LIBRUST_HASHES =    \
        unicode_width           19 \
        unwind                  20
 
+LIBRUST_HASHES_WASM32 = ${LIBRUST_HASHES} dlmalloc 21
+
 # generate a stable hash and pass it to build environment
 LIBRUST_HASH !=        echo '${FULLPKGNAME}:${TRIPLE_ARCH}' | sha1 | cut -c1-14
 .for _name _number in ${LIBRUST_HASHES}
@@ -122,6 +127,13 @@ LIBR_METADATA_${_name} =   ${LIBRUST_HASH}
 LIBRUST_ARGS +=        ${_name}=${LIBRUST_HASH}${_number}
 .endfor
 
+LIBRUST_HASH_WASM32 != echo '${FULLPKGNAME}:wasm32-unknown-unknown' | sha1 | 
cut -c1-14
+.for _name _number in ${LIBRUST_HASHES_WASM32}
+SUBST_VARS +=  LIBR_METADATA_WASM32_${_name}
+LIBR_METADATA_WASM32_${_name} =        ${LIBRUST_HASH_WASM32}${_number}
+LIBRUST_ARGS_WASM32 += ${_name}=${LIBRUST_HASH_WASM32}${_number}
+.endfor
+
 # on arches where the base compiler is clang: base-clang or ports-clang should 
be fine,
 # as we need devel/llvm only for libs.
 # on others archs, use ports-gcc as llvm libraries depends on libestdc++.so 
and libgcc.a.
@@ -149,6 +161,7 @@ RUN_DEPENDS-gdb +=  lang/rust,-main \
                        devel/gdb
 RUN_DEPENDS-clippy +=  lang/rust,-main
 RUN_DEPENDS-rustfmt += lang/rust,-main
+RUN_DEPENDS-wasm32  += lang/rust,-main
 
 MAKE_ENV +=    CARGO_HOME=${WRKBUILD}/cargo-home \
                TMPDIR=${WRKBUILD} \
@@ -235,6 +248,10 @@ do-configure:
                >>${WRKBUILD}/config.toml
 .endif
 
+       echo '[target.wasm32-unknown-unknown]' >>${WRKBUILD}/config.toml
+       echo 'llvm-config = "${LOCALBASE}/bin/llvm-config"' \
+               >>${WRKBUILD}/config.toml
+
 BUILD_BIN = cd ${WRKBUILD} && exec ${SETENV} ${MAKE_ENV} \
            ${MODPY_BIN} ${WRKSRC}/x.py
 TEST_BIN = cd ${WRKBUILD} && exec ${SETENV} ${MAKE_ENV} ${TEST_ENV} \
@@ -242,18 +259,18 @@ TEST_BIN = cd ${WRKBUILD} && exec ${SETE
 
 do-build:
        ${BUILD_BIN} dist --jobs=${MAKE_JOBS} \
-               rust-std rustc cargo clippy rustfmt
+               rust-std rustc cargo clippy rustfmt --target=${TRIPLE_ARCH} 
--target=wasm32-unknown-unknown
        rm -rf -- ${WRKBUILD}/build/tmp
 
-COMPONENTS ?=  rustc-${V} rust-std-${V} cargo-${V} \
-               clippy-${V} rustfmt-${V}
+COMPONENTS ?=  rustc-${V}-${TRIPLE_ARCH} rust-std-${V}-${TRIPLE_ARCH} 
cargo-${V}-${TRIPLE_ARCH} \
+               clippy-${V}-${TRIPLE_ARCH} rustfmt-${V}-${TRIPLE_ARCH} 
rust-std-${V}-wasm32-unknown-unknown
 do-install:
        rm -rf ${WRKBUILD}/_extractdist
 .for _c in ${COMPONENTS}
        mkdir ${WRKBUILD}/_extractdist
        cd ${WRKBUILD}/_extractdist && tar zxf \
-               ${WRKBUILD}/build/dist/${_c}-${TRIPLE_ARCH}.tar.gz
-       cd ${WRKBUILD}/_extractdist/${_c}-${TRIPLE_ARCH} && \
+               ${WRKBUILD}/build/dist/${_c}.tar.gz
+       cd ${WRKBUILD}/_extractdist/${_c} && \
                ${LOCALBASE}/bin/bash ./install.sh \
                --prefix="${PREFIX}" \
                --mandir="${PREFIX}/man"
@@ -265,6 +282,10 @@ do-install:
                ${PREFIX}/lib/rustlib/components \
                ${PREFIX}/lib/rustlib/manifest-*
        # rehash libraries to have stables filenames
+       # rehash wasm32 before TRIPLE_ARCH otherwise
+       # ${PREFIX}/lib/lib${name}-${oldhash}.so will be overwritten
+       cd ${PREFIX} && /bin/sh "${.CURDIR}/files/rehash.sh" 
wasm32-unknown-unknown ${LIBRUST_ARGS_WASM32}
+
        cd ${PREFIX} && /bin/sh "${.CURDIR}/files/rehash.sh" ${TRIPLE_ARCH} 
${LIBRUST_ARGS}
        # replace libraries by link
        for lib in ${PREFIX}/lib/lib*.* ; do \
Index: pkg/DESCR-wasm32
===================================================================
RCS file: pkg/DESCR-wasm32
diff -N pkg/DESCR-wasm32
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pkg/DESCR-wasm32    7 Sep 2022 12:06:17 -0000
@@ -0,0 +1 @@
+Provides WebAssembly toolchain (wasm32-unknown-unknown target)
Index: pkg/PLIST-wasm32
===================================================================
RCS file: pkg/PLIST-wasm32
diff -N pkg/PLIST-wasm32
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ pkg/PLIST-wasm32    7 Sep 2022 12:06:17 -0000
@@ -0,0 +1,29 @@
+lib/rustlib/
+lib/rustlib/wasm32-unknown-unknown/
+lib/rustlib/wasm32-unknown-unknown/lib/
+lib/rustlib/wasm32-unknown-unknown/lib/libaddr2line-${LIBR_METADATA_WASM32_addr2line}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libadler-${LIBR_METADATA_WASM32_adler}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/liballoc-${LIBR_METADATA_WASM32_alloc}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libcfg_if-${LIBR_METADATA_WASM32_cfg_if}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libcompiler_builtins-${LIBR_METADATA_WASM32_compiler_builtins}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libcore-${LIBR_METADATA_WASM32_core}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libdlmalloc-${LIBR_METADATA_WASM32_dlmalloc}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libgetopts-${LIBR_METADATA_WASM32_getopts}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libgimli-${LIBR_METADATA_WASM32_gimli}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libhashbrown-${LIBR_METADATA_WASM32_hashbrown}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/liblibc-${LIBR_METADATA_WASM32_libc}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libmemchr-${LIBR_METADATA_WASM32_memchr}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libminiz_oxide-${LIBR_METADATA_WASM32_miniz_oxide}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libobject-${LIBR_METADATA_WASM32_object}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libpanic_abort-${LIBR_METADATA_WASM32_panic_abort}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libpanic_unwind-${LIBR_METADATA_WASM32_panic_unwind}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libproc_macro-${LIBR_METADATA_WASM32_proc_macro}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/librustc_demangle-${LIBR_METADATA_WASM32_rustc_demangle}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_alloc-${LIBR_METADATA_WASM32_rustc_std_workspace_alloc}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_core-${LIBR_METADATA_WASM32_rustc_std_workspace_core}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/librustc_std_workspace_std-${LIBR_METADATA_WASM32_rustc_std_workspace_std}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libstd-${LIBR_METADATA_WASM32_std}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libstd_detect-${LIBR_METADATA_WASM32_std_detect}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libtest-${LIBR_METADATA_WASM32_test}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libunicode_width-${LIBR_METADATA_WASM32_unicode_width}.rlib
+lib/rustlib/wasm32-unknown-unknown/lib/libunwind-${LIBR_METADATA_WASM32_unwind}.rlib

Reply via email to