Skip to content

Commit e43adeb

Browse files
committed
Auto merge of #2510 - alexcrichton:xcompile, r=brson
Prepare for ARM/FreeBSD/NetBSD nightlies This commit beefs up Cargo's makefiles to support nightly builds of Cargo for multiple platforms. This primarily involves vendoring the logic of how to build OpenSSL for statically linking against Cargo into the Makefiles directly. We'll have to update the version of OpenSSL as releases are made, but we essentially already do that with the normal docker container. The Linux nightlies will still run in the normal dist docker container (a really old CentOS build) and builds for new platforms will happen in the standard linux-cross container we use for other cross builds. The nightly versions of these will produce Cargo tarballs for a whole bunch of platforms to get uploaded. This has been tested in the `alexcrichton/rust-slave-linux-cross:2016-03-17b` docker container for the 3 ARM targets and FreeBSD target. NetBSD will come once rust-lang/rust#32407 lands.
2 parents 61ad6a0 + 83b4f39 commit e43adeb

File tree

6 files changed

+143
-48
lines changed

6 files changed

+143
-48
lines changed

Cargo.lock

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.in

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
CFG_RELEASE_NUM=0.10.0
22
CFG_RELEASE_LABEL=
33

4+
OPENSSL_VERS=1.0.2g
5+
OPENSSL_SHA256=b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33
6+
47
include config.mk
58

69
ifneq ($(CFG_LOCAL_RUST_ROOT),)
@@ -46,6 +49,12 @@ else
4649
VERBOSE_FLAG=
4750
endif
4851

52+
ifdef CFG_CUSTOM_BUILD_DIR
53+
export CARGO_TARGET_DIR := $(CFG_CUSTOM_BUILD_DIR)
54+
endif
55+
56+
S := $(CFG_SRC_DIR)/
57+
4958
export CFG_VERSION
5059
export CFG_DISABLE_CROSS_TESTS
5160

@@ -81,19 +90,21 @@ endif
8190
all: $(foreach target,$(CFG_TARGET),cargo-$(target))
8291

8392
define CARGO_TARGET
84-
cargo-$(1): $$(CARGO)
93+
cargo-$(1): $$(CARGO) target/openssl/$(1).stamp
8594
$$(CFG_RUSTC) -V
8695
$$(CARGO) --version
87-
$$(CARGO) build --target $(1) $$(OPT_FLAG) $$(VERBOSE_FLAG) $$(ARGS)
96+
$$(CARGO) build --target $(1) \
97+
--manifest-path $(S)Cargo.toml \
98+
$$(OPT_FLAG) $$(VERBOSE_FLAG) $$(ARGS)
8899

89100
test-unit-$(1): $$(CARGO)
90101
@mkdir -p target/$(1)/cit
91102
$$(CARGO) test --target $(1) $$(VERBOSE_FLAG) $$(only)
92103
endef
93104
$(foreach target,$(CFG_TARGET),$(eval $(call CARGO_TARGET,$(target))))
94105

95-
$(TARGET_ROOT)/snapshot/bin/cargo$(X): src/snapshots.txt
96-
$(CFG_PYTHON) src/etc/dl-snapshot.py $(CFG_BUILD)
106+
$(TARGET_ROOT)/snapshot/bin/cargo$(X): $(S)src/snapshots.txt
107+
$(CFG_PYTHON) $(S)src/etc/dl-snapshot.py $(CFG_BUILD)
97108
touch $@
98109

99110

@@ -155,6 +166,76 @@ $(DOC_DIR)/%: src/doc/%
155166
@mkdir -p $(@D)
156167
cp $< $@
157168

169+
ifdef CFG_ENABLE_NIGHTLY
170+
171+
OPENSSL_OS_x86_64-unknown-linux-gnu := linux-x86_64
172+
OPENSSL_OS_x86_64-unknown-linux-musl := linux-x86_64
173+
OPENSSL_OS_i686-unknown-linux-gnu := linux-x32
174+
OPENSSL_OS_arm-unknown-linux-gnueabi := linux-armv4
175+
OPENSSL_OS_arm-unknown-linux-gnueabihf := linux-armv4
176+
OPENSSL_OS_armv7-unknown-linux-gnueabihf := linux-armv4
177+
OPENSSL_OS_x86_64-unknown-freebsd := BSD-x86_64
178+
OPENSSL_OS_x86_64-unknown-netbsd := BSD-x86_64
179+
180+
OPENSSL_CC_x86_64-unknown-linux-gnu := gcc
181+
OPENSSL_CC_x86_64-unknown-linux-musl := musl-gcc
182+
OPENSSL_CC_i686-unknown-linux-gnu := gcc
183+
OPENSSL_CC_arm-unknown-linux-gnueabi := arm-linux-gnueabi-gcc
184+
OPENSSL_CC_arm-unknown-linux-gnueabihf := arm-linux-gnueabihf-gcc
185+
OPENSSL_CC_armv7-unknown-linux-gnueabihf := armv7-linux-gnueabihf-gcc
186+
OPENSSL_CC_x86_64-unknown-freebsd := x86_64-unknown-freebsd10-gcc
187+
OPENSSL_CC_x86_64-unknown-netbsd := x86_64-unknown-netbsd-gcc
188+
OPENSSL_AR_x86_64-unknown-linux-gnu := ar
189+
OPENSSL_AR_x86_64-unknown-linux-musl := ar
190+
OPENSSL_AR_i686-unknown-linux-gnu := ar
191+
OPENSSL_AR_arm-unknown-linux-gnueabi := arm-linux-gnueabi-ar
192+
OPENSSL_AR_arm-unknown-linux-gnueabihf := arm-linux-gnueabihf-ar
193+
OPENSSL_AR_armv7-unknown-linux-gnueabihf := armv7-linux-gnueabihf-ar
194+
OPENSSL_AR_x86_64-unknown-freebsd := x86_64-unknown-freebsd10-ar
195+
OPENSSL_AR_x86_64-unknown-netbsd := x86_64-unknown-netbsd-ar
196+
197+
define BUILD_OPENSSL
198+
OPENSSL_INSTALL_$(1) := $$(CFG_BUILD_DIR)/target/openssl/$(1)-install
199+
200+
target/openssl/$(1).stamp: target/openssl/openssl-$$(OPENSSL_VERS).tar.gz \
201+
| target/openssl/
202+
mkdir -p target/openssl/$(1)
203+
tar xf $$< -C target/openssl/$(1) --strip-components 1
204+
(cd target/openssl/$(1) && \
205+
CC=$$(OPENSSL_CC_$(1)) \
206+
AR=$$(OPENSSL_AR_$(1)) \
207+
./Configure --prefix=$$(OPENSSL_INSTALL_$(1)) \
208+
no-dso $$(OPENSSL_OS_$(1)) -fPIC && \
209+
$(MAKE) -j10 && \
210+
$(MAKE) install)
211+
touch $$@
212+
213+
# variables read by various build scripts to find openssl
214+
cargo-$(1): export OPENSSL_STATIC := 1
215+
cargo-$(1): export OPENSSL_ROOT_DIR := $$(OPENSSL_INSTALL_$(1))
216+
cargo-$(1): export OPENSSL_LIB_DIR := $$(OPENSSL_INSTALL_$(1))/lib
217+
cargo-$(1): export OPENSSL_INCLUDE_DIR := $$(OPENSSL_INSTALL_$(1))/include
218+
219+
# build libz statically into the cargo we're producing
220+
cargo-$(1): export LIBZ_SYS_STATIC := 1
221+
endef
222+
223+
$(foreach target,$(CFG_TARGET),$(eval $(call BUILD_OPENSSL,$(target))))
224+
225+
target/openssl/openssl-$(OPENSSL_VERS).tar.gz: | target/openssl/
226+
curl -o $(@) https://openssl.org/source/openssl-$(OPENSSL_VERS).tar.gz
227+
sha256sum $(@) > $(@).sha256
228+
test $(OPENSSL_SHA256) = `cut -d ' ' -f 1 $(@).sha256`
229+
230+
target/openssl/:
231+
mkdir -p $(@)
232+
else
233+
define BUILD_OPENSSL
234+
target/openssl/$(1).stamp:
235+
endef
236+
$(foreach target,$(CFG_TARGET),$(eval $(call BUILD_OPENSSL,$(target))))
237+
endif
238+
158239
# === Distribution
159240

160241
define DO_DIST_TARGET
@@ -186,21 +267,23 @@ prepare-image-$(1):
186267
$$(IMGDIR_$(1))/share/zsh/site-functions \
187268
$$(IMGDIR_$(1))/etc/bash_completion.d
188269
cp $$(TARGET_$(1))/cargo$$(X) $$(IMGDIR_$(1))/bin
189-
cp src/etc/cargo.1 $$(IMGDIR_$(1))/share/man/man1
190-
cp src/etc/_cargo $$(IMGDIR_$(1))/share/zsh/site-functions/_cargo
191-
cp src/etc/cargo.bashcomp.sh $$(IMGDIR_$(1))/etc/bash_completion.d/cargo
192-
cp README.md LICENSE-MIT LICENSE-APACHE LICENSE-THIRD-PARTY \
270+
cp $(S)src/etc/cargo.1 $$(IMGDIR_$(1))/share/man/man1
271+
cp $(S)src/etc/_cargo $$(IMGDIR_$(1))/share/zsh/site-functions/_cargo
272+
cp $(S)src/etc/cargo.bashcomp.sh $$(IMGDIR_$(1))/etc/bash_completion.d/cargo
273+
cp $(S)README.md $(S)LICENSE-MIT $(S)LICENSE-APACHE \
274+
$(S)LICENSE-THIRD-PARTY \
193275
$$(IMGDIR_$(1))/share/doc/cargo
194276

195277
prepare-overlay-$(1):
196278
rm -Rf $$(OVERLAYDIR_$(1))
197279
mkdir -p $$(OVERLAYDIR_$(1))
198-
cp README.md LICENSE-MIT LICENSE-APACHE LICENSE-THIRD-PARTY \
280+
cp $(S)README.md $(S)LICENSE-MIT $(S)LICENSE-APACHE \
281+
$(S)LICENSE-THIRD-PARTY \
199282
$$(OVERLAYDIR_$(1))
200283
echo "$(CFG_VERSION)" > $$(OVERLAYDIR_$(1))/version
201284

202285
$$(DISTDIR_$(1))/$$(PKG_NAME)-$(1).tar.gz: prepare-image-$(1) prepare-overlay-$(1)
203-
sh src/rust-installer/gen-installer.sh \
286+
sh $(S)src/rust-installer/gen-installer.sh \
204287
--product-name=Rust \
205288
--rel-manifest-dir=rustlib \
206289
--success-message=Rust-is-ready-to-roll. \

configure

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,24 @@ done
366366
CFG_TARGET=$V_TEMP
367367

368368
if [ "$CFG_SRC_DIR" != "$CFG_BUILD_DIR" ]; then
369-
err "cargo does not currently support an out-of-tree build dir"
369+
CFG_CUSTOM_BUILD_DIR=$CFG_BUILD_DIR/target
370+
putvar CFG_CUSTOM_BUILD_DIR
370371
fi
371372

372373
if [ ! -z "$CFG_ENABLE_NIGHTLY" ]; then
373374
if [ ! -f .cargo/config ]; then
374375
mkdir -p .cargo
375376
cat > .cargo/config <<-EOF
376-
[target.x86_64-unknown-linux-gnu.openssl]
377-
rustc-flags = "-l static=ssl -l static=crypto -l dl -L /home/rustbuild/root64/lib"
378-
root = "/home/rustbuild/root64"
379-
include = "/home/rustbuild/root64/include"
380-
381-
[target.i686-unknown-linux-gnu.openssl]
382-
rustc-flags = "-l static=ssl -l static=crypto -l dl -L /home/rustbuild/root32/lib"
383-
root = "/home/rustbuild/root32"
384-
include = "/home/rustbuild/root32/include"
377+
[target.arm-unknown-linux-gnueabi]
378+
linker = "arm-linux-gnueabi-gcc"
379+
[target.arm-unknown-linux-gnueabihf]
380+
linker = "arm-linux-gnueabihf-gcc"
381+
[target.armv7-unknown-linux-gnueabihf]
382+
linker = "armv7-linux-gnueabihf-gcc"
383+
[target.x86_64-unknown-freebsd]
384+
linker = "x86_64-unknown-freebsd10-gcc"
385+
[target.x86_64-unknown-netbsd]
386+
linker = "x86_64-unknown-netbsd-gcc"
385387
EOF
386388
fi
387389
fi

src/etc/dl-snapshot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
current = None
1212
snaps = {}
13-
with open('src/snapshots.txt') as f:
13+
d = os.path.dirname(os.path.dirname(__file__))
14+
with open(d + '/snapshots.txt') as f:
1415
for line in iter(f):
1516
line = line.rstrip()
1617
m = datere.match(line)

src/rustversion.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2016-02-12
1+
2016-03-22

src/snapshots.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2016-03-21
2+
linux-i386 ac401c16ff53e0c51b88707579b4f95d7d4c4763
3+
linux-x86_64 84266cf626ca4fcdc290bca8f1a74e6ad9e8b3d9
4+
macos-i386 3550c653db2b8a41fdd7057339c923353081e7b0
5+
macos-x86_64 0372d52f6d06e3e18c8ffa6f016638b6d082770e
6+
winnt-i386 4bacbd3e0219f424740ce35e74a005b007a552aa
7+
winnt-x86_64 8fc67036c4c76fbfa1d8532d9b9ac923f9060001
8+
19
2016-01-31
210
linux-i386 7e2f9c82e1af5aa43ef3ee2692b985a5f2398f0a
311
linux-x86_64 4c03a3fd2474133c7ad6d8bb5f6af9915ca5292a

0 commit comments

Comments
 (0)