Skip to content

Instantly share code, notes, and snippets.

@swills
Created February 9, 2023 16:29
Show Gist options
  • Save swills/eca79ee0f119965dbb834afc327761b0 to your computer and use it in GitHub Desktop.
Save swills/eca79ee0f119965dbb834afc327761b0 to your computer and use it in GitHub Desktop.
diff --git lang/rust/Makefile lang/rust/Makefile
index d2e9273fbf6f..0ee8ab74b99c 100644
--- lang/rust/Makefile
+++ lang/rust/Makefile
@@ -48,8 +48,13 @@ CONFLICTS_INSTALL?= rust-nightly
# ?= to allow users to still overwrite it in make.conf.
TMPDIR?= ${WRKDIR}
+.if defined(NIGHTLY_DATE)
OPTIONS_DEFINE= DOCS GDB SOURCES WASM
OPTIONS_DEFAULT= SOURCES WASM
+.else
+OPTIONS_DEFINE= DOCS GDB SOURCES WASM WASI
+OPTIONS_DEFAULT= SOURCES WASM WASI
+.endif
.if !defined(NIGHTLY_DATE)
OPTIONS_EXCLUDE= DOCS # https://github.com/rust-lang/rust/issues/76526
.endif
@@ -57,6 +62,7 @@ OPTIONS_EXCLUDE= DOCS # https://github.com/rust-lang/rust/issues/76526
GDB_DESC= Install ports gdb (necessary for debugging rust programs)
SOURCES_DESC= Install source files
WASM_DESC= Build the WebAssembly target (wasm32-unknown-unknown)
+WASI_DESC= Build the WASI target (wasm32-wasi)
DOCS_VARS= _RUST_BUILD_DOCS=true
DOCS_VARS_OFF= _RUST_BUILD_DOCS=false
@@ -67,6 +73,11 @@ WASM_VARS= _COMPONENTS+="rust-analysis-${_PACKAGE_VERS}-wasm32-unknown-unknown
_RUST_BUILD_WASM=true \
_RUST_TARGETS+=wasm32-unknown-unknown
WASM_VARS_OFF= _RUST_BUILD_WASM=false
+WASI_VARS= _RUST_TARGETS+=wasm32-wasi \
+ _COMPONENTS+="rust-analysis-${_PACKAGE_VERS}-wasm32-wasi rust-std-${_PACKAGE_VERS}-wasm32-wasi"
+WASI_BUILD_DEPENDS= wasi-compiler-rt13>0:devel/wasi-compiler-rt13 \
+ ${LOCALBASE}/share/wasi-sysroot/include/__errno.h:devel/wasi-libc \
+ llvm13>=0:devel/llvm13
# See WRKSRC/src/stage0.json for the date and version values
BOOTSTRAPS_DATE?= 2022-11-03
@@ -218,7 +229,7 @@ do-configure:
@${PRINTF} '#!/bin/sh\nexec ${CC} -fuse-ld=bfd "$$@" --target=powerpc-unknown-freebsd13.0' > ${WRKDIR}/ld-wrapper
@${CHMOD} +x ${WRKDIR}/ld-wrapper
.endif
-.for _target in ${_RUST_TARGETS}
+.for _target in ${_RUST_TARGETS:S,wasm32-wasi,,}
@${ECHO_CMD} '[target.${_target}]' >> ${WRKSRC}/config.toml
@${ECHO_CMD} 'ar="${AR}"' >> ${WRKSRC}/config.toml
.if ${ARCH} == powerpc
@@ -240,6 +251,12 @@ do-configure:
# Don't abort if optional tools fail to build
@${ECHO_CMD} 'missing-tools=true' >> ${WRKSRC}/config.toml
.endif
+ @${ECHO_CMD} '[target.wasm32-wasi]' >> ${WRKSRC}/config.toml
+ @${ECHO_CMD} 'ar="llvm-ar13"' >> ${WRKSRC}/config.toml
+ @${ECHO_CMD} 'cc="clang13"' >> ${WRKSRC}/config.toml
+ @${ECHO_CMD} 'cxx="clang++13"' >> ${WRKSRC}/config.toml
+ @${ECHO_CMD} 'linker="clang13"' >> ${WRKSRC}/config.toml
+ @${ECHO_CMD} "wasi-root=\"${PREFIX}/share/wasi-sysroot\"" >> ${WRKSRC}/config.toml
do-build:
@cd ${WRKSRC} && \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment