]> git.proxmox.com Git - rustc.git/blobdiff - debian/rules
Use remap-path-prefix flags for a reproducible build
[rustc.git] / debian / rules
index 747be3f33a2f1afbed65aa5ff68ecc97975d23a6..6f45274964898c944f796940556d86b611b70d28 100755 (executable)
@@ -6,7 +6,8 @@ include /usr/share/dpkg/vendor.mk
 include /usr/share/dpkg/architecture.mk
 include /usr/share/dpkg/buildflags.mk
 # TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml
-RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
+RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS)) \
+ -Zremap-path-prefix-from=$(CURDIR) -Zremap-path-prefix-to=/usr/src/rust
 export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
 
 # Defines DEB_*_RUST_TYPE triples
@@ -34,17 +35,25 @@ RUST_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | $(SED_VERSION_SHORT))
 RUST_LONG_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -re 's/([^+]+).*/\1/')
 LIBSTD_PKG := libstd-rust-$(RUST_VERSION)
 # Sed expression that matches the "rustc" we have in our Build-Depends field
-SED_RUSTC_BUILDDEP := sed -ne "/^Build-Depends:/,/^[^[:space:]\#]/{/^ *rustc .*,/p}" debian/control
+SED_RUSTC_BUILDDEP := sed -ne "/^Build-Depends:/,/^[^[:space:]\#]/{/^ *rustc:native .*,/p}" debian/control
 
 # These are the normal build flags. Upstream is moving to debian/config.toml
 # but at the current version not all of these flags are available in that file.
-DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr
+# Certain flags also need to be kept here *as well as* debian/config.toml.in
+# because of https://github.com/rust-lang/rust/issues/43295
+DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr --release-channel=$(RELEASE_CHANNEL) --disable-debuginfo-only-std
 
 # Use system LLVM (comment out to use vendored LLVM)
-OLD_LLVM_VERSION = 3.8
-DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-3.9
-RUSTBUILD = ./x.py
-RUSTBUILD_FLAGS = --config debian/config.toml -v
+LLVM_VERSION = 4.0
+OLD_LLVM_VERSION = 3.9
+DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-$(LLVM_VERSION)
+RUSTBUILD = RUST_BACKTRACE=1 ./x.py
+RUSTBUILD_FLAGS = --config debian/config.toml -v --on-fail env
+# To run a specific test, run something like:
+#   $ debian/rules override_dh_auto_test-arch \
+#     RUSTBUILD_TEST_FLAGS="src/test/run-make --test-args extern-fn-struct"
+# See src/bootstrap/README.md for more options.
+RUSTBUILD_TEST_FLAGS =
 
 update-version:
        oldver=$(shell $(SED_RUSTC_BUILDDEP) | sed -ne 's/.*(<= \(.*\)).*/\1/gp' | $(SED_VERSION_SHORT)); \
@@ -101,36 +110,65 @@ ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
   DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
 endif
 
-# Workaround for powerpc64le: no optimization
-# TODO: can remove when https://github.com/rust-lang/rust/issues/39015 is fixed
-ifneq (,$(findstring powerpc64le,$(DEB_TARGET_RUST_TYPE)))
-  DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
-endif
-
 # Build products or non-source files in src/, that shouldn't go in rust-src
 SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
        src/bootstrap/bootstrap.pyc \
        src/etc/__pycache__/
 
+# Workaround for linux #865549
+ifeq (0,$(shell test $$(uname -s) = "Linux" -a $$(getconf PAGESIZE) -gt 4096; echo $$?))
+  SYSTEM_WORKAROUNDS += ulimit -s $$(expr $$(getconf PAGESIZE) / 1024 '*' 256 + 8192);
+endif
+
 %:
-       dh $@ --parallel
+       $(SYSTEM_WORKAROUNDS) dh $@ --parallel
 
 .PHONY: build
 build:
-       dh $@ --parallel
+       $(SYSTEM_WORKAROUNDS) dh $@ --parallel
+
+override_dh_clean:
+       dh_clean -Xsrc/vendor/bitflags/Cargo.toml.orig
+
+debian/configure-upstream: debian/config.toml debian/rules
+       rm -f "$@"
+       echo '#!/bin/sh' >> "$@"
+       echo '# This script can be used to configure a mostly-clean upstream checkout' >> "$@"
+       echo '# in case you need to test any differences between it and Debian' >> "$@"
+       echo 'set -e' >> "$@"
+       echo 'test -f ./configure' >> "$@"
+       echo 'cat > config.toml <<EOF' >> "$@"
+       cat debian/config.toml >> "$@"
+       echo 'EOF' >> "$@"
+       echo "./configure $(DEB_CONFIGURE_FLAGS)" >> "$@"
+       chmod +x "$@"
 
 debian/config.toml: debian/config.toml.in
        m4  -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
                -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
                -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
                -DRELEASE_CHANNEL="$(RELEASE_CHANNEL)" \
+               -DLLVM_VERSION="$(LLVM_VERSION)" \
                "$<" > "$@"
 
 override_dh_auto_configure: debian/config.toml
        # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
-       ! grep --color=always -i 'll...?$(OLD_LLVM_VERSION)' --exclude=changelog -R debian
+       ! grep --color=always -i 'll...\?$(subst .,\.,$(OLD_LLVM_VERSION))' --exclude=changelog -R debian
        $(PRECONFIGURE_CHECK)
        if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi
+       # work around #842634
+       if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \
+         debian/ensure-patch -N debian/patches/d-host-duplicates.patch; fi
+       # We patched mdbook so have to rm the checksums
+       debian/empty-cargo-checksum.py src/vendor/mdbook/.cargo-checksum.json
+       # Unfortunately upstream uses a duplicate copy of libbacktrace and wants to
+       # compile it again for rust-installer, see #43449
+       ln -rsf src/libbacktrace -t src/vendor/backtrace-sys/src/
+       debian/empty-cargo-checksum.py src/vendor/backtrace-sys/.cargo-checksum.json
+       # Link against system liblzma, see https://github.com/alexcrichton/xz2-rs/issues/16
+       echo 'fn main() { println!("cargo:rustc-link-lib=lzma"); }' > src/vendor/lzma-sys/build.rs
+       debian/empty-cargo-checksum.py src/vendor/lzma-sys/.cargo-checksum.json
+       # Do the actual configure
        PATH="$$PWD/debian/bin:$$PATH" \
            ./configure $(DEB_CONFIGURE_FLAGS)
 
@@ -155,12 +193,8 @@ ifneq (,$(BUILD_DOCS))
        $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
 endif
 
-override_dh_auto_test-arch:
-ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
-# Use non-parallel $(MAKE) here instead of dh_auto_test, otherwise the upstream
-# Makefile will try to run N instances of the testrunner each of which will run
-# N instances of rustc (there is also parallel logic in libtest.rs already).
-       if RUST_BACKTRACE=1 $(RUSTBUILD) test $(RUSTBUILD_FLAGS); then \
+RUN_TESTS = \
+       if $(1); then \
          : ; \
        elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
          false; \
@@ -171,16 +205,31 @@ ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
          echo "WARNING: Ignoring test failures in the rust testsuite"; \
          echo "====================================================="; \
        fi
+
+override_dh_auto_test-arch:
+# ensure that rustc_llvm is actually dynamically linked to libLLVM
+       set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \
+       while read x; do \
+               stat -c '%s %n' "$$x"; \
+               objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \
+               test "$$(stat -c %s "$$x")" -lt 6000000; \
+       done
+ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
+       $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS))
+# don't continue if RUSTBUILD_TEST_FLAGS is non-empty
+       test -z "$(RUSTBUILD_TEST_FLAGS)"
 endif
 
-# No tests are applicable when only building arch:all packages.
-# More specifically: when we do an arch-all build, some crates are not built.
-# This makes some arch-dependent tests fail, so don't run them here.
 override_dh_auto_test-indep:
-       true
+ifneq (,$(BUILD_DOCS))
+ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
+       # Run all rules that test the docs, i.e. in step.rs that depend on default:doc
+       $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast src/tools/linkchecker $(RUSTBUILD_FLAGS))
+endif
+endif
 
 override_dh_auto_install:
-       DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) dist $(RUSTBUILD_FLAGS) --install
+       DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS)
 
        mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
        mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
@@ -229,7 +278,6 @@ override_dh_install-indep:
                \) -delete
        cd debian/rust-src/usr/src/rust && chmod -x \
                src/etc/gdb_rust_pretty_printing.py \
-               src/etc/adb_run_wrapper.sh \
                src/compiler-rt/test/builtins/Unit/ppc/test
 
 override_dh_installchangelogs: