summaryrefslogtreecommitdiff
path: root/lang/rust-bootstrap/Makefile
blob: 45d0358fc877b0c30036588c1462a8c4183bb25a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Once the bootstraps are available on pkg.FreeBSD.org run sync.sh
# to upload them to ~/public_distfiles on freefall in preparation
# for the next lang/rust update.
PORTNAME=	rust
PORTVERSION=	1.63.0
CATEGORIES=	lang
MASTER_SITES=	https://static.rust-lang.org/dist/
PKGNAMEPREFIX=	${FLAVOR:S/_/-/g}-
PKGNAMESUFFIX=	-bootstrap
DISTNAME=	${PORTNAME}c-${PORTVERSION}-src
DIST_SUBDIR=	rust

MAINTAINER=	rust@FreeBSD.org
COMMENT=	Create bootstrap compilers for building lang/rust

LICENSE=	APACHE20 MIT
LICENSE_COMB=	dual
LICENSE_FILE_APACHE20=	${WRKSRC}/LICENSE-APACHE
LICENSE_FILE_MIT=	${WRKSRC}/LICENSE-MIT

ONLY_FOR_ARCHS=	amd64 powerpc64le
ONLY_FOR_ARCHS_REASON=	untested on other architectures

BUILD_DEPENDS=	${FLAVOR:S/_/-/g}-freebsd-sysroot>=a2021.09.14:devel/freebsd-sysroot@${FLAVOR} \
		cmake:devel/cmake \
		gmake:devel/gmake \
		rust>=${PORTVERSION}:lang/rust

FLAVORS=	aarch64 amd64 armv6 armv7 i386 powerpc64_elfv1 powerpc64_elfv2 \
		powerpc64le powerpc riscv64
FLAVOR?=	${FLAVORS:[1]}

USES=		cpe ninja:build perl5 python:3.6+,build tar:xz
CPE_VENDOR=	${PORTNAME}-lang
.if ${FLAVOR} == powerpc64_elfv1
USE_GCC=	9:build
.endif
# for openssl-src crate
USE_PERL5=	build
PATCHDIR=	${.CURDIR}/../rust/files
# rustc stashes intermediary files in TMPDIR (default /tmp) which
# might cause issues for users that for some reason space limit
# their /tmp.  WRKDIR should have plenty of space.
# ?= to allow users to still overwrite it in make.conf.
TMPDIR?=	${WRKDIR}
# Resulting packages are not specific to amd64
NO_ARCH=	yes

_CARGO_VENDOR_DIR=			${WRKSRC}/vendor
_RUST_ARCH_amd64=			x86_64
_RUST_ARCH_i386=			i686
_RUST_ARCH_powerpc64_elfv1=		powerpc64
_RUST_ARCH_powerpc64_elfv2=		powerpc64
_RUST_ARCH_riscv64=			riscv64gc
_RUST_HOST=				${_RUST_ARCH_${ARCH}:U${ARCH}}-unknown-${OPSYS:tl}
_RUST_TARGET=				${_RUST_ARCH_${FLAVOR}:U${FLAVOR}}-unknown-${OPSYS:tl}
_RUST_LLVM_TARGET=			${_RUST_LLVM_TARGET_${FLAVOR}}
_RUST_LLVM_TARGET_aarch64=		AArch64
_RUST_LLVM_TARGET_amd64=		X86
_RUST_LLVM_TARGET_armv6=		ARM
_RUST_LLVM_TARGET_armv7=		ARM
_RUST_LLVM_TARGET_i386=			X86
_RUST_LLVM_TARGET_powerpc64_elfv1=	PowerPC
_RUST_LLVM_TARGET_powerpc64_elfv2=	PowerPC
_RUST_LLVM_TARGET_powerpc64le=		PowerPC
_RUST_LLVM_TARGET_powerpc=		PowerPC
_RUST_LLVM_TARGET_riscv64=		RISCV

.include <bsd.port.pre.mk>

.if ${OPSYS} != FreeBSD
IGNORE=	is only for FreeBSD
.endif
.if (${FLAVOR} == powerpc64le || ${FLAVOR} == riscv64) && ${OSVERSION} < 1300116
IGNORE=	will not build on 12.x due to old system
.endif

.if exists(${PATCHDIR}/${FLAVOR:S/_/-/})
EXTRA_PATCHES+=	${PATCHDIR}/${FLAVOR:S/_/-/}
.endif

post-patch:
# Disable vendor checksums
	@${REINPLACE_CMD} 's,"files":{[^}]*},"files":{},' \
		${_CARGO_VENDOR_DIR}/*/.cargo-checksum.json
.if ${FLAVOR} == powerpc64_elfv1
	@${REINPLACE_CMD} -e 's,"c++","stdc++",g' \
		${WRKSRC}/compiler/rustc_llvm/build.rs
	@${REINPLACE_CMD} -e 's,%CC%,${CC},g' \
		-e 's,%WRKDIR%,${LOCALBASE}/freebsd-sysroot/powerpc64-elfv1,g' \
		${WRKSRC}/compiler/rustc_llvm/build.rs \
		${WRKSRC}/src/bootstrap/native.rs
.endif

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}" \
		${SH} ${SCRIPTSDIR}/rust-compat11-canary.sh
	@${ECHO_CMD} 'changelog-seen=2' > ${WRKSRC}/config.toml
	@${ECHO_CMD} '[build]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'build-dir="${WRKDIR}/_build"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'vendor=true' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'extended=false' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'python="${PYTHON_CMD}"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'docs=false' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'verbose=2' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cargo-native-static=true' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cargo="${LOCALBASE}/bin/cargo"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'rustc="${LOCALBASE}/bin/rustc"' >> ${WRKSRC}/config.toml
.if ${_RUST_HOST} != ${_RUST_TARGET}
	@${ECHO_CMD} 'host=["${_RUST_HOST}","${_RUST_TARGET}"]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'target=["${_RUST_TARGET}"]' >> ${WRKSRC}/config.toml
.endif
	@${ECHO_CMD} '[rust]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'channel="stable"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'default-linker="${CC}"' >> ${WRKSRC}/config.toml
.if ${FLAVOR} == riscv64
	@${ECHO_CMD} 'debug=true' >> ${WRKSRC}/config.toml
.endif
	@${ECHO_CMD} 'deny-warnings=false' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} '[llvm]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'link-shared=false' >> ${WRKSRC}/config.toml
.if ${FLAVOR} == powerpc64_elfv1
	@${ECHO_CMD} 'static-libstdcpp=true' >> ${WRKSRC}/config.toml
.endif
.if defined(WITH_CCACHE_BUILD) && !defined(NO_CCACHE)
	@${ECHO_CMD} 'ccache="${CCACHE_BIN}"' >> ${WRKSRC}/config.toml
.else
	@${ECHO_CMD} 'ccache=false' >> ${WRKSRC}/config.toml
.endif
# https://github.com/rust-lang/rust/pull/72696#issuecomment-641517185
	@${ECHO_CMD} 'ldflags="-lz"' >> ${WRKSRC}/config.toml
# we need to make sure to always build llvm with host arch support to get a
# host compiler that can build the host->target compiler
	@${ECHO_CMD} 'targets="${_RUST_LLVM_TARGET};${_RUST_LLVM_TARGET_${ARCH}}"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} '[target.${_RUST_TARGET}]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cc="${LOCALBASE}/freebsd-sysroot/${FLAVOR:S/_/-/g}/bin/cc"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cxx="${LOCALBASE}/freebsd-sysroot/${FLAVOR:S/_/-/g}/bin/c++"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'linker="${LOCALBASE}/freebsd-sysroot/${FLAVOR:S/_/-/g}/bin/cc"' >> ${WRKSRC}/config.toml
.for _key _util in ar ${AR} ranlib ${RANLIB}
	@bin="$$(which ${_util})"; \
		${ECHO_CMD} "${_key}=\"$$bin\"" >> ${WRKSRC}/config.toml
.endfor
.if ${_RUST_HOST} != ${_RUST_TARGET}
	@${ECHO_CMD} '[target.${_RUST_HOST}]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cc="${CC}"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'cxx="${CXX}"' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'linker="${CC}"' >> ${WRKSRC}/config.toml
.endif
	@${ECHO_CMD} '[dist]' >> ${WRKSRC}/config.toml
	@${ECHO_CMD} 'src-tarball=false' >> ${WRKSRC}/config.toml

do-build:
	@cd ${WRKSRC} && \
		${SETENV} ${MAKE_ENV} ${PYTHON_CMD} x.py dist --jobs=${MAKE_JOBS_NUMBER} \
		cargo rustc rust-std

do-install:
	@${MKDIR} ${STAGEDIR}${PREFIX}/rust-bootstrap/${FLAVOR}
	${INSTALL_DATA} ${WRKDIR}/_build/dist/*-${_RUST_ARCH_${FLAVOR}:U${FLAVOR}}-unknown-${OPSYS:tl}${EXTRACT_SUFX} \
		${STAGEDIR}${PREFIX}/rust-bootstrap/${FLAVOR}
.if ${FLAVOR:Mpowerpc64_*}
	@cd ${STAGEDIR}${PREFIX}/rust-bootstrap/${FLAVOR} && for f in *${EXTRACT_SUFX}; do \
		${MV} $$f $${f%%${EXTRACT_SUFX}}-${FLAVOR:S/_/ /:[2]}${EXTRACT_SUFX}; \
	done
.endif
	@cd ${STAGEDIR}${PREFIX} && \
		${FIND} rust-bootstrap -type f >> ${TMPPLIST}

.include <bsd.port.post.mk>