Skip to content

Commit

Permalink
lang/rust: resurrect PORT_LLVM as a non-default OPTION
Browse files Browse the repository at this point in the history
Rust uses LLVM for code generation [0] and bundles their own copy
of a release that they fully support in relation to the rest of
rustc. This however adds to an already intensive build process. For
the benefit of those building from source, resurrect the PORT_LLVM
option, allowing to link with an existing devel/llvm port of the
user's choosing within Rust compatibility ranges. This remains unset
by default.

PORT_LLVM was removed during an era when Rust tracked LLVM trunk,
during the LLVM 7.0 development cycle. Starting with LLVM 8.0, Rust
tracks LLVM releases with upstream cherry-picks, similar to our
base system LLVM process. [1] Additionally, instead of making changes
directly in their bundled LLVM, llvm-wrapper takes care of anything
needed in that area. [2] Issues stemming from this option have since
been resolved or overcome.

[0] https://rustc-dev-guide.rust-lang.org/backend/codegen.html
[1] https://rustc-dev-guide.rust-lang.org/backend/updating-llvm.html
[2] https://github.com/rust-lang/rust/tree/master/compiler/rustc_llvm/llvm-wrapper

Co-authored-by: Evgeniy Khramtsov <2khramtsov_gmail.com>
Approved by: tobik (rust)
Differential Revision: https://reviews.freebsd.org/D32654
  • Loading branch information
vishwin committed Oct 9, 2023
1 parent 8548e6a commit 098de5b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 24 additions & 4 deletions lang/rust/Makefile
Expand Up @@ -48,10 +48,11 @@ CONFLICTS_INSTALL?= rust-nightly
# ?= to allow users to still overwrite it in make.conf.
TMPDIR?= ${WRKDIR}

OPTIONS_DEFINE= DOCS GDB LTO SOURCES WASM
OPTIONS_DEFINE= DOCS GDB LTO PORT_LLVM SOURCES WASM
OPTIONS_DEFAULT= SOURCES WASM

GDB_DESC= Install ports gdb (necessary for debugging rust programs)
PORT_LLVM_DESC= Build against devel/llvm instead of bundled copy (experimental)
SOURCES_DESC= Install source files
WASM_DESC= Build the WebAssembly target (wasm32-unknown-unknown)

Expand All @@ -60,12 +61,12 @@ DOCS_VARS= _RUST_BUILD_DOCS=true \
_RUST_TOOLS+=rustdoc
DOCS_VARS_OFF= _RUST_BUILD_DOCS=false
GDB_RUN_DEPENDS= ${LOCALBASE}/bin/gdb:devel/gdb
PORT_LLVM_USES= llvm:min=14,lib,noexport
PORT_LLVM_MAKE_ENV= RUSTFLAGS="-Lnative=${LOCALBASE}/lib"
SOURCES_VARS= _COMPONENTS+=rust-src-${_PACKAGE_VERS} \
_RUST_TOOLS+=src
WASM_VARS= _COMPONENTS+="rust-analysis-${_PACKAGE_VERS}-wasm32-unknown-unknown rust-std-${_PACKAGE_VERS}-wasm32-unknown-unknown" \
_RUST_BUILD_WASM=true \
_RUST_TARGETS+=wasm32-unknown-unknown
WASM_VARS_OFF= _RUST_BUILD_WASM=false

# See WRKSRC/src/stage0.json for the date and version values
BOOTSTRAPS_DATE?= 2023-07-13
Expand Down Expand Up @@ -95,6 +96,13 @@ _COMPONENTS+= cargo-${_PACKAGE_VERS}-${_RUST_TARGET} \

.include <bsd.port.pre.mk>

.ifndef NIGHTLY_DATE
PATCH_SITES= https://github.com/rust-lang/rust/commit/
# LLVM 17 API compatibility fixes
PATCHFILES= 71958da4854176c50a8b12470b956d5c7ed11817.patch:-p1 \
6ddf9128b2b55f9def80af57f7353d2521527c6a.patch:-p1
.endif

.if ${OPSYS} != FreeBSD
IGNORE= is only for FreeBSD
.endif
Expand Down Expand Up @@ -156,6 +164,11 @@ post-patch:
@${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \
${CARGO_VENDOR_DIR}/*/.cargo-checksum.json

post-patch-PORT_LLVM-on:
# WASM target hardcodes bundled lld
@${REINPLACE_CMD} 's|"rust-lld"|"wasm-ld${LLVM_DEFAULT}"|' \
${WRKSRC}/compiler/rustc_target/src/spec/wasm_base.rs

do-configure:
# Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64
@${SETENV} CC="${CC}" OPSYS="${OPSYS}" OSVERSION="${OSVERSION}" WRKDIR="${WRKDIR}" \
Expand Down Expand Up @@ -190,7 +203,11 @@ do-configure:
@${ECHO_CMD} 'default-linker="${CC}"' >> ${WRKSRC}/config.toml
@${ECHO_CMD} 'deny-warnings=false' >> ${WRKSRC}/config.toml
@${ECHO_CMD} 'verbose-tests=true' >> ${WRKSRC}/config.toml
@${ECHO_CMD} 'lld=${_RUST_BUILD_WASM}' >> ${WRKSRC}/config.toml
.if ${PORT_OPTIONS:MWASM} && !${PORT_OPTIONS:MPORT_LLVM}
@${ECHO_CMD} 'lld=true' >> ${WRKSRC}/config.toml
.else
@${ECHO_CMD} 'lld=false' >> ${WRKSRC}/config.toml
.endif
.if ${PORT_OPTIONS:MLTO}
@${ECHO_CMD} 'lto="thin"' >> ${WRKSRC}/config.toml
.endif
Expand Down Expand Up @@ -230,6 +247,9 @@ do-configure:
.else
@${ECHO_CMD} 'linker="${CC}"' >> ${WRKSRC}/config.toml
.endif
.if ${PORT_OPTIONS:MPORT_LLVM}
@${ECHO_CMD} 'llvm-config="${LOCALBASE}/bin/${LLVM_CONFIG}"' >> ${WRKSRC}/config.toml
.endif
.endfor
@${ECHO_CMD} '[dist]' >> ${WRKSRC}/config.toml
@${ECHO_CMD} 'src-tarball=false' >> ${WRKSRC}/config.toml
Expand Down
4 changes: 4 additions & 0 deletions lang/rust/distinfo
Expand Up @@ -49,3 +49,7 @@ SHA256 (rust/2023-07-13/rust-std-1.71.0-riscv64gc-unknown-freebsd.tar.xz) = 4ca3
SIZE (rust/2023-07-13/rust-std-1.71.0-riscv64gc-unknown-freebsd.tar.xz) = 24375500
SHA256 (rust/2023-07-13/cargo-1.71.0-riscv64gc-unknown-freebsd.tar.xz) = b49977e17a42a9175cfa016941a6006f8e188f610f4ed59945f114fcb9f04820
SIZE (rust/2023-07-13/cargo-1.71.0-riscv64gc-unknown-freebsd.tar.xz) = 10130160
SHA256 (rust/71958da4854176c50a8b12470b956d5c7ed11817.patch) = 5a6b67dfc1218ea953421816834ffe3aa8ac1fc078dfaea4ebab121460ca5211
SIZE (rust/71958da4854176c50a8b12470b956d5c7ed11817.patch) = 2007
SHA256 (rust/6ddf9128b2b55f9def80af57f7353d2521527c6a.patch) = 6eaaaf6714c496b610712aa9ecbe1a1614e042323ec872fbf31a0a74c9020f29
SIZE (rust/6ddf9128b2b55f9def80af57f7353d2521527c6a.patch) = 1278

0 comments on commit 098de5b

Please sign in to comment.