Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Oct 2023 15:30:55 GMT
From:      Charlie Li <vishwin@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 098de5bc2195 - main - lang/rust: resurrect PORT_LLVM as a non-default OPTION
Message-ID:  <202310091530.399FUtvL000587@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by vishwin:

URL: https://cgit.FreeBSD.org/ports/commit/?id=098de5bc2195a064523eb32e7db6071b2f8ed93a

commit 098de5bc2195a064523eb32e7db6071b2f8ed93a
Author:     Charlie Li <vishwin@FreeBSD.org>
AuthorDate: 2023-09-25 19:56:30 +0000
Commit:     Charlie Li <vishwin@FreeBSD.org>
CommitDate: 2023-10-09 15:30:33 +0000

    lang/rust: resurrect PORT_LLVM as a non-default OPTION
    
    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
---
 lang/rust/Makefile | 28 ++++++++++++++++++++++++----
 lang/rust/distinfo |  4 ++++
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/lang/rust/Makefile b/lang/rust/Makefile
index 9c2cb3a7b5d4..414c065264dc 100644
--- a/lang/rust/Makefile
+++ b/lang/rust/Makefile
@@ -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)
 
@@ -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
@@ -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
@@ -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}" \
@@ -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
@@ -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
diff --git a/lang/rust/distinfo b/lang/rust/distinfo
index 8ae91f752136..2beb9b476377 100644
--- a/lang/rust/distinfo
+++ b/lang/rust/distinfo
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202310091530.399FUtvL000587>