]> git.proxmox.com Git - rustc.git/blobdiff - debian/rules
Use remap-path-prefix flags for a reproducible build
[rustc.git] / debian / rules
index 277c9cde17b44e9a42ee7bc9e3e29cc28ff7f6e0..6f45274964898c944f796940556d86b611b70d28 100755 (executable)
@@ -2,35 +2,25 @@
 # -*- makefile -*-
 
 include /usr/share/dpkg/pkg-info.mk
+include /usr/share/dpkg/vendor.mk
 include /usr/share/dpkg/architecture.mk
 include /usr/share/dpkg/buildflags.mk
-#RUSTFLAGS = -C link-args="$(LDFLAGS)"
-# temporary workaround for https://github.com/rust-lang/rust/issues/31529
-# this will FAIL if LDFLAGS itself contains shell-interpreted chars beyond
-# unquoted spaces (that addprefix works around the failure of)
-RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
+# TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml
+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
 include debian/architecture.mk
+export DEB_HOST_RUST_TYPE
 
 # Uncomment this to turn on verbose mode.
 #export DH_VERBOSE=1
 
-# When using sudo pbuilder, this will cause mk/install.mk to run sudo,
-# but we don't need sudo as a build-dep for the package if we unexport
-# the SUDO_USER variable.
-unexport SUDO_USER
-
 # src/rt/miniz.c (incorrectly) triggers -Wmisleading-indentation with
 # gcc-6.  See bug #811573.
 CFLAGS += -Wno-misleading-indentation
 
-# Debhelper clears MAKEFLAGS, so we have to do this again for any
-# target where we call $(MAKE) directly.  Boo.
-DEB_PARALLEL_JOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
-PMAKE = $(MAKE) $(if $(DEB_PARALLEL_JOBS),-j$(DEB_PARALLEL_JOBS))
-
 # Release type (one of beta, stable or nightly)
 RELEASE_CHANNEL := stable
 # See also ./build-preview-dsc.sh for a script that builds a beta/nightly .dsc
@@ -40,25 +30,74 @@ RELEASE_CHANNEL := stable
 
 DEB_DESTDIR := $(CURDIR)/debian/tmp
 
-RUST_VERSION := $(shell dpkg-parsechangelog --show-field Version | sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/')
+SED_VERSION_SHORT := sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/'
+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:native .*,/p}" debian/control
 
-# These are the normal build flags
-DEB_CONFIGURE_FLAGS = \
-               --host=$(DEB_HOST_RUST_TYPE) \
-               --target=$(DEB_TARGET_RUST_TYPE) \
-               --disable-manage-submodules \
-               --release-channel=$(RELEASE_CHANNEL) \
-               --prefix=/usr
+# 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.
+# 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)
-DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-3.7
-
-ifeq (,$(findstring dlstage0,$(DEB_BUILD_PROFILES)))
-# With the dlstage0 profile, rust build scripts will look for a pre-built
-# stage0 in dl/. This can either be satisfied by the make_orig-dl_tarball.sh
-# script, or else the build scripts will download these from rust-lang.org.
-  DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
+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)); \
+       newver=$(RUST_VERSION); \
+       if [ $$oldver != $$newver ]; then debian/update-version.sh $$oldver $$newver; fi
+
+# Below we detect how we're supposed to bootstrap the stage0 compiler. See
+# README.Debian for more details of the cases described below.
+#
+PRECONFIGURE_CHECK = :
+HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
+# allow not using the binary tarball although it exists
+#ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
+#  HAVE_BINARY_TARBALL := 0
+#endif
+ifeq (0,$(HAVE_BINARY_TARBALL))
+    # Case A (Building from source): the extracted source tree does not include
+    # a bootstrapping tarball for the current architecture e.g. because the
+    # distro already has a rustc for this arch, or the uploader expects that
+    # this requirement be fulfilled in some other way.
+    #
+    # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
+    # In this case, we use the distro's rustc - either the previous or current version.
+    ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
+        DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
+    endif
+    #
+    # Case A-2: the builder selected the "dlstage0" build profile.
+    # In this case, the rust build scripts will download a stage0 into stage0/ and use that.
+    # We don't need to do anything specific in this build file, so this case is empty.
+else
+    # Case B (Bootstrapping a new distro): the extracted source tree does
+    # include a bootstrapping tarball for the current architecture; see the
+    # `source_orig-stage0` target below on how to build this.
+    #
+    # In this case, we'll bootstrap from the stage0 given in that tarball.
+    # To ensure the uploader of the .dsc didn't make a mistake, we first check
+    # that rustc isn't a Build-Depends for the current architecture.
+    ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
+    ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
+        PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \
+          but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
+    endif
+    endif
 endif
 
 BUILD_DOCS = 1
@@ -71,33 +110,126 @@ ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
   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__/
 
-%:
-       dh $@ --parallel
+# 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
 
-# Note: SHELL is not set by dash, but the configure script wants to use it
-override_dh_auto_configure:
-       SHELL=/bin/sh PATH="$$PWD/debian/bin:$$PATH" \
+%:
+       $(SYSTEM_WORKAROUNDS) dh $@ --parallel
+
+.PHONY: build
+build:
+       $(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...\?$(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)
-#      test "$$($(MAKE) --no-print-directory print-CFG_FILENAME_EXTRA | tail -n1 | cut -d= -f2)" = "$$(echo $(RUST_VERSION))"
-
 
 override_dh_auto_clean:
-       set -e; \
-       if [ -f Makefile ]; then \
-         $(PMAKE) clean-all; \
-         $(RM) Makefile config.stamp; \
+       $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile
+       $(RM) -rf $(SRC_CLEAN) debian/config.toml
+
+# upstream bundles this in the source, but in Debian we rebuild everything yo
+generate-sources:
+       $(MAKE) -C src/rt/hoedown src/html_blocks.c
+
+override_dh_auto_build-arch: generate-sources
+       $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
+
+# note: this is only for buildds that want to do a separate arch:all build;
+# there is no point running this yourself "to save time" since it implicitly
+# depends on build-arch anyways.
+override_dh_auto_build-indep: generate-sources
+ifneq (,$(BUILD_DOCS))
+# Rust has a weird way of configuring whether to build docs or not
+       sed -i -e 's/^docs = false/docs = true/' debian/config.toml
+       $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
+endif
+
+RUN_TESTS = \
+       if $(1); then \
+         : ; \
+       elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
+         false; \
+       elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \
+         false ; \
+       else \
+         echo "====================================================="; \
+         echo "WARNING: Ignoring test failures in the rust testsuite"; \
+         echo "====================================================="; \
        fi
-       $(RM) src/etc/snapshot.pyc
 
-override_dh_auto_build-arch:
-       dh_auto_build -- all VERBOSE=1
+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
 
-override_dh_auto_build-indep:
-       $(if $(BUILD_DOCS),dh_auto_build -- docs)
+override_dh_auto_test-indep:
+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:
-       dh_auto_install --destdir=$(DEB_DESTDIR)
+       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)/
@@ -123,17 +255,30 @@ ifneq (,$(BUILD_DOCS))
          sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
               -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
        done
-
-       find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete
+       find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
 endif
 
 override_dh_install-arch:
        dh_install
        dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
 
+override_dh_install-indep:
+       dh_install
        chmod -x \
          debian/rust-gdb/usr/share/rust-gdb/*.py \
          debian/rust-lldb/usr/share/rust-lldb/*.py
+       $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%)
+       # Get rid of lintian warnings
+       find debian/rust-src/usr/src/rust \
+               \( -name .gitignore \
+               -o -name 'LICENSE*' \
+               -o -name 'LICENCE' \
+               -o -name 'license' \
+               -o -name 'COPYING*' \
+               \) -delete
+       cd debian/rust-src/usr/src/rust && chmod -x \
+               src/etc/gdb_rust_pretty_printing.py \
+               src/compiler-rt/test/builtins/Unit/ppc/test
 
 override_dh_installchangelogs:
        dh_installchangelogs RELEASES.md
@@ -144,18 +289,13 @@ override_dh_installdocs:
 override_dh_compress:
        dh_compress -X.woff
 
-override_dh_auto_test:
-ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
-       RUST_BACKTRACE=1 $(PMAKE) VERBOSE=1 check-notidy
-endif
-
 override_dh_makeshlibs:
        dh_makeshlibs -V
 
        # dh_makeshlibs doesn't support our "libfoo-version.so" naming
        # structure, so we have to do this ourselves.
        install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
-       ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
+       LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
        sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
        while read name version; do \
          echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
@@ -165,3 +305,11 @@ override_dh_makeshlibs:
 
 override_dh_shlibdeps:
        dh_shlibdeps -- -x$(LIBSTD_PKG)
+
+QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
+source_orig-stage0:
+       QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
+       $(MAKE) -f debian/rules clean
+       debian/make_orig-stage0_tarball.sh
+       QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
+       rm -rf .pc