Skip to content

Commit

Permalink
Auto merge of #2510 - alexcrichton:xcompile, r=brson
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Mar 23, 2016
2 parents 61ad6a0 + 83b4f39 commit e43adeb
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 48 deletions.
53 changes: 27 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 93 additions & 10 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
CFG_RELEASE_NUM=0.10.0
CFG_RELEASE_LABEL=

OPENSSL_VERS=1.0.2g
OPENSSL_SHA256=b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33

include config.mk

ifneq ($(CFG_LOCAL_RUST_ROOT),)
Expand Down Expand Up @@ -46,6 +49,12 @@ else
VERBOSE_FLAG=
endif

ifdef CFG_CUSTOM_BUILD_DIR
export CARGO_TARGET_DIR := $(CFG_CUSTOM_BUILD_DIR)
endif

S := $(CFG_SRC_DIR)/

export CFG_VERSION
export CFG_DISABLE_CROSS_TESTS

Expand Down Expand Up @@ -81,19 +90,21 @@ endif
all: $(foreach target,$(CFG_TARGET),cargo-$(target))

define CARGO_TARGET
cargo-$(1): $$(CARGO)
cargo-$(1): $$(CARGO) target/openssl/$(1).stamp
$$(CFG_RUSTC) -V
$$(CARGO) --version
$$(CARGO) build --target $(1) $$(OPT_FLAG) $$(VERBOSE_FLAG) $$(ARGS)
$$(CARGO) build --target $(1) \
--manifest-path $(S)Cargo.toml \
$$(OPT_FLAG) $$(VERBOSE_FLAG) $$(ARGS)

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

$(TARGET_ROOT)/snapshot/bin/cargo$(X): src/snapshots.txt
$(CFG_PYTHON) src/etc/dl-snapshot.py $(CFG_BUILD)
$(TARGET_ROOT)/snapshot/bin/cargo$(X): $(S)src/snapshots.txt
$(CFG_PYTHON) $(S)src/etc/dl-snapshot.py $(CFG_BUILD)
touch $@


Expand Down Expand Up @@ -155,6 +166,76 @@ $(DOC_DIR)/%: src/doc/%
@mkdir -p $(@D)
cp $< $@

ifdef CFG_ENABLE_NIGHTLY

OPENSSL_OS_x86_64-unknown-linux-gnu := linux-x86_64
OPENSSL_OS_x86_64-unknown-linux-musl := linux-x86_64
OPENSSL_OS_i686-unknown-linux-gnu := linux-x32
OPENSSL_OS_arm-unknown-linux-gnueabi := linux-armv4
OPENSSL_OS_arm-unknown-linux-gnueabihf := linux-armv4
OPENSSL_OS_armv7-unknown-linux-gnueabihf := linux-armv4
OPENSSL_OS_x86_64-unknown-freebsd := BSD-x86_64
OPENSSL_OS_x86_64-unknown-netbsd := BSD-x86_64

OPENSSL_CC_x86_64-unknown-linux-gnu := gcc
OPENSSL_CC_x86_64-unknown-linux-musl := musl-gcc
OPENSSL_CC_i686-unknown-linux-gnu := gcc
OPENSSL_CC_arm-unknown-linux-gnueabi := arm-linux-gnueabi-gcc
OPENSSL_CC_arm-unknown-linux-gnueabihf := arm-linux-gnueabihf-gcc
OPENSSL_CC_armv7-unknown-linux-gnueabihf := armv7-linux-gnueabihf-gcc
OPENSSL_CC_x86_64-unknown-freebsd := x86_64-unknown-freebsd10-gcc
OPENSSL_CC_x86_64-unknown-netbsd := x86_64-unknown-netbsd-gcc
OPENSSL_AR_x86_64-unknown-linux-gnu := ar
OPENSSL_AR_x86_64-unknown-linux-musl := ar
OPENSSL_AR_i686-unknown-linux-gnu := ar
OPENSSL_AR_arm-unknown-linux-gnueabi := arm-linux-gnueabi-ar
OPENSSL_AR_arm-unknown-linux-gnueabihf := arm-linux-gnueabihf-ar
OPENSSL_AR_armv7-unknown-linux-gnueabihf := armv7-linux-gnueabihf-ar
OPENSSL_AR_x86_64-unknown-freebsd := x86_64-unknown-freebsd10-ar
OPENSSL_AR_x86_64-unknown-netbsd := x86_64-unknown-netbsd-ar

define BUILD_OPENSSL
OPENSSL_INSTALL_$(1) := $$(CFG_BUILD_DIR)/target/openssl/$(1)-install

target/openssl/$(1).stamp: target/openssl/openssl-$$(OPENSSL_VERS).tar.gz \
| target/openssl/
mkdir -p target/openssl/$(1)
tar xf $$< -C target/openssl/$(1) --strip-components 1
(cd target/openssl/$(1) && \
CC=$$(OPENSSL_CC_$(1)) \
AR=$$(OPENSSL_AR_$(1)) \
./Configure --prefix=$$(OPENSSL_INSTALL_$(1)) \
no-dso $$(OPENSSL_OS_$(1)) -fPIC && \
$(MAKE) -j10 && \
$(MAKE) install)
touch $$@

# variables read by various build scripts to find openssl
cargo-$(1): export OPENSSL_STATIC := 1
cargo-$(1): export OPENSSL_ROOT_DIR := $$(OPENSSL_INSTALL_$(1))
cargo-$(1): export OPENSSL_LIB_DIR := $$(OPENSSL_INSTALL_$(1))/lib
cargo-$(1): export OPENSSL_INCLUDE_DIR := $$(OPENSSL_INSTALL_$(1))/include

# build libz statically into the cargo we're producing
cargo-$(1): export LIBZ_SYS_STATIC := 1
endef

$(foreach target,$(CFG_TARGET),$(eval $(call BUILD_OPENSSL,$(target))))

target/openssl/openssl-$(OPENSSL_VERS).tar.gz: | target/openssl/
curl -o $(@) https://openssl.org/source/openssl-$(OPENSSL_VERS).tar.gz
sha256sum $(@) > $(@).sha256
test $(OPENSSL_SHA256) = `cut -d ' ' -f 1 $(@).sha256`

target/openssl/:
mkdir -p $(@)
else
define BUILD_OPENSSL
target/openssl/$(1).stamp:
endef
$(foreach target,$(CFG_TARGET),$(eval $(call BUILD_OPENSSL,$(target))))
endif

# === Distribution

define DO_DIST_TARGET
Expand Down Expand Up @@ -186,21 +267,23 @@ prepare-image-$(1):
$$(IMGDIR_$(1))/share/zsh/site-functions \
$$(IMGDIR_$(1))/etc/bash_completion.d
cp $$(TARGET_$(1))/cargo$$(X) $$(IMGDIR_$(1))/bin
cp src/etc/cargo.1 $$(IMGDIR_$(1))/share/man/man1
cp src/etc/_cargo $$(IMGDIR_$(1))/share/zsh/site-functions/_cargo
cp src/etc/cargo.bashcomp.sh $$(IMGDIR_$(1))/etc/bash_completion.d/cargo
cp README.md LICENSE-MIT LICENSE-APACHE LICENSE-THIRD-PARTY \
cp $(S)src/etc/cargo.1 $$(IMGDIR_$(1))/share/man/man1
cp $(S)src/etc/_cargo $$(IMGDIR_$(1))/share/zsh/site-functions/_cargo
cp $(S)src/etc/cargo.bashcomp.sh $$(IMGDIR_$(1))/etc/bash_completion.d/cargo
cp $(S)README.md $(S)LICENSE-MIT $(S)LICENSE-APACHE \
$(S)LICENSE-THIRD-PARTY \
$$(IMGDIR_$(1))/share/doc/cargo

prepare-overlay-$(1):
rm -Rf $$(OVERLAYDIR_$(1))
mkdir -p $$(OVERLAYDIR_$(1))
cp README.md LICENSE-MIT LICENSE-APACHE LICENSE-THIRD-PARTY \
cp $(S)README.md $(S)LICENSE-MIT $(S)LICENSE-APACHE \
$(S)LICENSE-THIRD-PARTY \
$$(OVERLAYDIR_$(1))
echo "$(CFG_VERSION)" > $$(OVERLAYDIR_$(1))/version

$$(DISTDIR_$(1))/$$(PKG_NAME)-$(1).tar.gz: prepare-image-$(1) prepare-overlay-$(1)
sh src/rust-installer/gen-installer.sh \
sh $(S)src/rust-installer/gen-installer.sh \
--product-name=Rust \
--rel-manifest-dir=rustlib \
--success-message=Rust-is-ready-to-roll. \
Expand Down
22 changes: 12 additions & 10 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,24 @@ done
CFG_TARGET=$V_TEMP

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

if [ ! -z "$CFG_ENABLE_NIGHTLY" ]; then
if [ ! -f .cargo/config ]; then
mkdir -p .cargo
cat > .cargo/config <<-EOF
[target.x86_64-unknown-linux-gnu.openssl]
rustc-flags = "-l static=ssl -l static=crypto -l dl -L /home/rustbuild/root64/lib"
root = "/home/rustbuild/root64"
include = "/home/rustbuild/root64/include"
[target.i686-unknown-linux-gnu.openssl]
rustc-flags = "-l static=ssl -l static=crypto -l dl -L /home/rustbuild/root32/lib"
root = "/home/rustbuild/root32"
include = "/home/rustbuild/root32/include"
[target.arm-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
[target.armv7-unknown-linux-gnueabihf]
linker = "armv7-linux-gnueabihf-gcc"
[target.x86_64-unknown-freebsd]
linker = "x86_64-unknown-freebsd10-gcc"
[target.x86_64-unknown-netbsd]
linker = "x86_64-unknown-netbsd-gcc"
EOF
fi
fi
Expand Down
3 changes: 2 additions & 1 deletion src/etc/dl-snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

current = None
snaps = {}
with open('src/snapshots.txt') as f:
d = os.path.dirname(os.path.dirname(__file__))
with open(d + '/snapshots.txt') as f:
for line in iter(f):
line = line.rstrip()
m = datere.match(line)
Expand Down
2 changes: 1 addition & 1 deletion src/rustversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2016-02-12
2016-03-22
8 changes: 8 additions & 0 deletions src/snapshots.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2016-03-21
linux-i386 ac401c16ff53e0c51b88707579b4f95d7d4c4763
linux-x86_64 84266cf626ca4fcdc290bca8f1a74e6ad9e8b3d9
macos-i386 3550c653db2b8a41fdd7057339c923353081e7b0
macos-x86_64 0372d52f6d06e3e18c8ffa6f016638b6d082770e
winnt-i386 4bacbd3e0219f424740ce35e74a005b007a552aa
winnt-x86_64 8fc67036c4c76fbfa1d8532d9b9ac923f9060001

2016-01-31
linux-i386 7e2f9c82e1af5aa43ef3ee2692b985a5f2398f0a
linux-x86_64 4c03a3fd2474133c7ad6d8bb5f6af9915ca5292a
Expand Down

0 comments on commit e43adeb

Please sign in to comment.