]> git.proxmox.com Git - rustc.git/blame - debian/rules
bump version to 1.71.1+dfsg1-1~bpo12+pve1
[rustc.git] / debian / rules
CommitLineData
be771b38
LB
1#!/usr/bin/make -f
2# -*- makefile -*-
3
b59979d9 4include /usr/share/dpkg/pkg-info.mk
6472c211 5include /usr/share/dpkg/vendor.mk
d75d48d6 6include /usr/share/dpkg/architecture.mk
b5dfb68c
XL
7SED_VERSION_SHORT := sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/'
8RUST_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | $(SED_VERSION_SHORT))
9RUST_LONG_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -re 's/([^+]+).*/\1/')
10LIBSTD_PKG := libstd-rust-$(RUST_VERSION)
11# Sed expression that matches the "rustc" we have in our Build-Depends field
12SED_RUSTC_BUILDDEP := sed -ne "/^Build-Depends:/,/^[^[:space:]\#]/{/^ *rustc:native .*,/p}" debian/control
2da5f2f9
XL
13# Version of /usr/bin/rustc
14LOCAL_RUST_VERSION := $(shell rustc --version --verbose | sed -ne 's/^release: //p')
b5dfb68c 15
7d40d3e1 16include /usr/share/dpkg/buildflags.mk
8a3e0ada
FG
17# needed for cross-compilation to avoid passing host CFLAGS to the BUILD
18# compiler
19export TARGET_CFLAGS = $(CFLAGS)
20export TARGET_CXXFLAGS = $(CXXFLAGS)
21export TARGET_CPPFLAGS = $(CPPFLAGS)
22export TARGET_LDFLAGS = $(LDFLAGS)
23unexport CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
ca38e697 24export CARGO_HOME = $(CURDIR)/debian/cargo
b59979d9 25
525ff0f9
AL
26# Defines DEB_*_RUST_TYPE triples
27include debian/architecture.mk
eede8545 28# for dh_install substitution variable
693daed7 29export DEB_HOST_RUST_TYPE
525ff0f9 30
eede8545
XL
31# for dh_install substitution variable
32export RUST_LONG_VERSION
be771b38 33
8354de7a 34DEB_DESTDIR := $(CURDIR)/debian/tmp
525ff0f9 35
525ff0f9 36# Use system LLVM (comment out to use vendored LLVM)
a383e2ad
FG
37LLVM_VERSION = 16
38OLD_LLVM_VERSION = 15
7e45ca5b 39# Cargo-specific flags
40export LIBSSH2_SYS_USE_PKG_CONFIG=1
2b7c35b5
XL
41# Make it easier to test against a custom LLVM
42ifneq (,$(LLVM_DESTDIR))
56548b60
XL
43LLVM_LIBRARY_PATH := $(LLVM_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH):$(LLVM_DESTDIR)/usr/lib
44LD_LIBRARY_PATH := $(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):$(LLVM_LIBRARY_PATH),$(LLVM_LIBRARY_PATH))
2b7c35b5
XL
45export LD_LIBRARY_PATH
46endif
2b7c35b5 47
6a1b7eba
AS
48# Required for profiler builtin
49CLANG_RT_ARCH := $(DEB_TARGET_GNU_CPU)
50ifeq (i386,$(DEB_TARGET_ARCH))
51CLANG_RT_ARCH = i386
52endif
53ifeq (armhf,$(DEB_TARGET_ARCH))
54CLANG_RT_ARCH = armhf
55endif
a6f2bf1b 56
fc6de811 57ifneq (,$(filter $(DEB_TARGET_ARCH),sparc64 mips64el))
0aa1f5c3
FG
58# sparc64: see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1061125
59# mips64el: has profiler, but buggy atm (32-bit overflow in some counter?)
a6f2bf1b
FG
60CLANG_RT_ARCH =
61PROFILER = "false"
62else
5f832760 63export LLVM_PROFILER_RT_LIB=/usr/lib/llvm-$(LLVM_VERSION)/lib/clang/$(LLVM_VERSION)/lib/linux/libclang_rt.profile-$(CLANG_RT_ARCH).a
a6f2bf1b
FG
64PROFILER = "true"
65endif
6a1b7eba 66
84acf1d1
XL
67ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
68NJOBS := -j $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
69endif
70RUSTBUILD = RUST_BACKTRACE=1 python3 src/bootstrap/bootstrap.py $(NJOBS)
2f6e6584 71RUSTBUILD_FLAGS = --stage 2 --config debian/config.toml --on-fail env
f9fab79c
XL
72# rust-tidy depends on lots of modules that we strip out of the build.
73# it also tries to access the network for some reason. so just disable it.
74RUSTBUILD_TEST = $(RUSTBUILD) test --no-fail-fast --exclude src/tools/tidy
0d3674eb
XL
75# To run a specific test, run something like:
76# $ debian/rules override_dh_auto_test-arch \
77# RUSTBUILD_TEST_FLAGS="src/test/run-make --test-args extern-fn-struct"
78# See src/bootstrap/README.md for more options.
79RUSTBUILD_TEST_FLAGS =
1c8ac2b0 80
831ac0bf
XL
81# https://github.com/rust-lang/rust/issues/89744
82# TODO: remove when we update cargo to 1.55 / 0.56
83# upstream bug still exists and is under investigation, but is hidden by newer cargo
19b13fcc 84export CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=0
831ac0bf 85
25f1c2fe
XL
86update-version:
87 oldver=$(shell $(SED_RUSTC_BUILDDEP) | sed -ne 's/.*(<= \(.*\)).*/\1/gp' | $(SED_VERSION_SHORT)); \
0bf22a45
XL
88 newver=$(RUST_VERSION); \
89 debian/update-version.sh $$oldver $$newver $(RUST_LONG_VERSION) $(CARGO_NEW)
25f1c2fe 90
427dce5b
XL
91# Below we detect how we're supposed to bootstrap the stage0 compiler. See
92# README.Debian for more details of the cases described below.
93#
427dce5b 94PRECONFIGURE_CHECK = :
75be2bb3 95HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
5861ebac 96DOWNLOAD_BOOTSTRAP := false
571f0d20
MK
97# allow not using the binary tarball although it exists
98#ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
99# HAVE_BINARY_TARBALL := 0
100#endif
101ifeq (0,$(HAVE_BINARY_TARBALL))
16dfb283
XL
102 # Case A (Building from source): the extracted source tree does not include
103 # a bootstrapping tarball for the current architecture e.g. because the
104 # distro already has a rustc for this arch, or the uploader expects that
105 # this requirement be fulfilled in some other way.
427dce5b
XL
106 #
107 # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
108 # In this case, we use the distro's rustc - either the previous or current version.
109 ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
56548b60
XL
110 # Make it easier to test against a custom rustc
111 ifneq (,$(RUST_DESTDIR))
112 RUST_LIBRARY_PATH := $(RUST_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH):$(RUST_DESTDIR)/usr/lib
113 LD_LIBRARY_PATH := $(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):$(RUST_LIBRARY_PATH),$(RUST_LIBRARY_PATH))
114 export LD_LIBRARY_PATH
115 endif
427dce5b
XL
116 #
117 # Case A-2: the builder selected the "dlstage0" build profile.
75be2bb3 118 # In this case, the rust build scripts will download a stage0 into stage0/ and use that.
b9a40c91 119 # We don't need to do anything specific in this build file, so this case is empty.
5861ebac
XL
120 else
121 DOWNLOAD_BOOTSTRAP := true
122 endif
427dce5b 123else
16dfb283
XL
124 # Case B (Bootstrapping a new distro): the extracted source tree does
125 # include a bootstrapping tarball for the current architecture; see the
75be2bb3 126 # `source_orig-stage0` target below on how to build this.
427dce5b
XL
127 #
128 # In this case, we'll bootstrap from the stage0 given in that tarball.
129 # To ensure the uploader of the .dsc didn't make a mistake, we first check
16dfb283 130 # that rustc isn't a Build-Depends for the current architecture.
25f1c2fe
XL
131 ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
132 ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
75be2bb3 133 PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \
16dfb283
XL
134 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
135 endif
427dce5b 136 endif
1c8ac2b0
SL
137endif
138
5861ebac 139BUILD_DOCS := true
120b4d47 140ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
5861ebac 141 BUILD_DOCS := false
1c8ac2b0 142endif
005427f4
XL
143ifneq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
144 BUILD_DOCS := false
145endif
1c8ac2b0 146
8d2dc69d
XL
147BUILD_WASM := true
148ifneq (,$(findstring nowasm,$(DEB_BUILD_PROFILES)))
149 BUILD_WASM := false
150endif
151
511691db 152WINDOWS_SUPPORT := amd64 i386
27da05fd
XL
153BUILD_WINDOWS := true
154ifneq (,$(findstring nowindows,$(DEB_BUILD_PROFILES)))
155 BUILD_WINDOWS := false
156endif
247218ad 157ifeq (,$(filter $(DEB_HOST_ARCH), $(WINDOWS_SUPPORT)))
27da05fd
XL
158 BUILD_WINDOWS := false
159else
247218ad 160 ifeq (,$(filter $(DEB_BUILD_ARCH), $(WINDOWS_SUPPORT)))
27da05fd
XL
161 ifeq (true,$(BUILD_WINDOWS))
162 $(error cannot cross-compile from $(DEB_BUILD_ARCH) to $(DEB_HOST_ARCH), unless "nowindows" is in DEB_BUILD_PROFILES)
163 endif
164 endif
165 ifeq (i386,$(DEB_HOST_ARCH))
166 WINDOWS_ARCH := i686
167 else
168 WINDOWS_ARCH := x86_64
169 endif
170endif
eede8545
XL
171# for dh_install substitution variable
172export WINDOWS_ARCH
27da05fd 173
5861ebac 174MAKE_OPTIMISATIONS := true
1c8ac2b0 175ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
5861ebac 176 MAKE_OPTIMISATIONS := false
1c8ac2b0
SL
177endif
178
2f6e6584
XL
179VERBOSITY_SUB := $(words $(filter terse,$(DEB_BUILD_OPTIONS)))
180VERBOSITY_ADD := $(words $(filter verbose,$(DEB_BUILD_OPTIONS)))
181VERBOSITY := $(shell expr 2 + $(VERBOSITY_ADD) - $(VERBOSITY_SUB))
182
aca8be47
XL
183ifeq ($(shell test $(VERBOSITY) -ge 3; echo $$?),0)
184 export DH_VERBOSE=1
185endif
186
187ifeq ($(shell test $(VERBOSITY) -le 0; echo $$?),0)
188 export DH_QUIET=1
189.SILENT:
190endif
191
35329365 192# Build products or non-source files in src/, that shouldn't go in rust-src
9a2ab7ea 193SRC_CLEAN = src/bootstrap/bootstrap.pyc \
d35683cb 194 src/bootstrap/__pycache__ \
35329365 195 src/etc/__pycache__/
1c8ac2b0 196
96a6ef5f
XL
197# Try to work around #933045
198ifneq (,$(filter $(DEB_BUILD_ARCH), mips mipsel))
199 SYSTEM_WORKAROUNDS += export MALLOC_ARENA_MAX=1;
200endif
170f9149 201
be771b38 202%:
370db491 203 $(SYSTEM_WORKAROUNDS) dh $@ --parallel --with bash-completion
be771b38 204
27da05fd
XL
205.PHONY: .dbg-windows
206.dbg-windows:
207 @echo host=$(DEB_BUILD_ARCH) target=$(DEB_HOST_ARCH) BUILD_WINDOWS=$(BUILD_WINDOWS) WINDOWS_ARCH=$(WINDOWS_ARCH)
208
04c12273
XL
209.PHONY: build
210build:
370db491 211 $(SYSTEM_WORKAROUNDS) dh $@ --parallel --with bash-completion
04c12273 212
de1de54b 213override_dh_clean:
cf0b146d
XL
214 # Upstream contains a lot of these
215 dh_clean -XCargo.toml.orig
de1de54b 216
b49766ad
XL
217debian/config.toml: debian/config.toml.in debian/rules
218 u="$(DEB_VERSION_UPSTREAM)"; \
219 if [ "$$u" != "$${u%~beta.*+dfsg*}" ]; then channel="beta"; \
aca8be47 220 else channel="stable"; fi; \
ec028c2e
XL
221 m4 -DRELEASE_CHANNEL="$$channel" \
222 -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
01dc6ef4
XL
223 -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
224 -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
ec028c2e
XL
225 -DDEB_BUILD_GNU_TYPE="$(DEB_BUILD_GNU_TYPE)" \
226 -DDEB_HOST_GNU_TYPE="$(DEB_HOST_GNU_TYPE)" \
227 -DDEB_TARGET_GNU_TYPE="$(DEB_TARGET_GNU_TYPE)" \
5861ebac 228 -DMAKE_OPTIMISATIONS="$(MAKE_OPTIMISATIONS)" \
2f6e6584 229 -DVERBOSITY="$(VERBOSITY)" \
2b7c35b5 230 -DLLVM_DESTDIR="$(LLVM_DESTDIR)" \
666f0397 231 -DLLVM_VERSION="$(LLVM_VERSION)" \
5861ebac 232 -DRUST_DESTDIR="$(RUST_DESTDIR)" \
a6f2bf1b 233 -DPROFILER="$(PROFILER)" \
01dc6ef4 234 "$<" > "$@"
7ee10b55
XL
235 if $(DOWNLOAD_BOOTSTRAP) || [ $(HAVE_BINARY_TARBALL) != 0 ]; \
236 then sed -i -e '/^rustc = /d' -e '/^cargo = /d' "$@"; fi
e8cad677 237# Work around low-memory (32-bit) architectures: https://github.com/rust-lang/rust/issues/45854
a3aaf3d3
FG
238# i386 and x32 fail to mmap rustc_driver when building rustdoc in >1.60
239ifneq (,$(filter $(DEB_BUILD_ARCH), armhf armel i386 mips mipsel powerpc powerpcspe x32))
bae0839e 240 sed -i -e 's/^debuginfo-level = .*/debuginfo-level = 0/g' "$@"
8978aae4 241endif
01dc6ef4 242
61fad94a 243check-no-old-llvm:
5617e1bd 244 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
3aade234 245 ! grep --color=always -i '\(clang\|ll\(..\|d\)\)-\?$(subst .,\.,$(OLD_LLVM_VERSION))' --exclude=changelog --exclude=copyright --exclude='*.patch' --exclude-dir='.debhelper' -R debian
61fad94a
XL
246.PHONY: check-no-old-llvm
247
18a275f7
FG
248extra-vendor:
249 if [ -d extra ]; then \
250 cd extra; \
251 for c in *; do \
252 if [ -e ../vendor/"$$c" ]; then \
253 mv -v ../vendor/"$$c" ../vendor/"$$c".backup ; \
254 fi ; \
255 echo "adding extra vendored dependency '$$c'"; \
256 cp -r ./"$$c" ../vendor/; \
257 done; \
258 fi
259
260.PHONY: extra-vendor
261
262debian/dh_auto_configure.stamp: debian/config.toml check-no-old-llvm extra-vendor
c54b4d09 263 # fail the build if we accidentally vendored openssl, indicates we pulled in unnecessary dependencies
43e09c12 264 test ! -e vendor/openssl-src
e133b084 265 # fail the build if our version contains ~exp and we are not releasing to experimental
b49766ad 266 v="$(DEB_VERSION)"; test "$$v" = "$${v%~exp*}" -o "$(DEB_DISTRIBUTION)" = "experimental" -o "$(DEB_DISTRIBUTION)" = "UNRELEASED"
427dce5b 267 $(PRECONFIGURE_CHECK)
75be2bb3 268 if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi
3281855a
XL
269 # work around #842634
270 if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \
6c577aa0 271 debian/ensure-patch -N debian/patches/d-test-host-duplicates.patch; fi
a93d58bc 272 # don't care about lock changes
14fc8225 273 rm -f Cargo.lock src/bootstrap/Cargo.lock src/tools/rust-analyzer/Cargo.lock src/tools/cargo/Cargo.lock
98955da7 274 # We patched some crates so have to rm the checksums
94bd9ad3 275 find vendor -name .cargo-checksum.json -execdir "$(CURDIR)/debian/prune-checksums" "{}" +
6b0d97fc 276 # Link against system liblzma, see https://github.com/alexcrichton/xz2-rs/issues/16
f56f18fe 277 echo 'fn main() { println!("cargo:rustc-link-lib=lzma"); }' > vendor/lzma-sys/build.rs
5861ebac
XL
278 # We don't run ./configure because we use debian/config.toml directly
279 ln -sf debian/config.toml config.toml
3bdf427a
XL
280 touch "$@"
281
282override_dh_auto_configure-arch: debian/dh_auto_configure.stamp
283override_dh_auto_configure-indep: debian/dh_auto_configure.stamp
284ifeq (true,$(BUILD_DOCS))
285# Change config.toml now and not later, since that might trigger a rebuild
286 sed -i -e 's/^docs = false/docs = true/' debian/config.toml
287endif
1c8ac2b0 288
11c430be 289override_dh_auto_clean:
94b8d793 290 $(RM) -rf build tmp debian/cargo_home config.stamp config.mk Makefile
b8189452 291 $(RM) -rf $(TEST_LOG) debian/config.toml debian/*.stamp
5b2524c4 292 $(RM) -rf $(SRC_CLEAN) config.toml
11c430be 293
809d6012 294debian/dh_auto_build.stamp:
04c12273 295 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
ea192313 296
809d6012 297override_dh_auto_build-arch: debian/dh_auto_build.stamp
27da05fd
XL
298ifeq (true,$(BUILD_WINDOWS))
299 $(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
300 --host $(DEB_BUILD_RUST_TYPE) \
301 --target $(WINDOWS_ARCH)-pc-windows-gnu \
830de2ed 302 library/std
27da05fd
XL
303endif
304
809d6012 305override_dh_auto_build-indep: debian/dh_auto_build.stamp
8d2dc69d 306ifeq (true,$(BUILD_WASM))
8978aae4 307 $(RUSTBUILD) build $(RUSTBUILD_FLAGS) \
910f03de
XL
308 --host $(DEB_BUILD_RUST_TYPE) \
309 --target wasm32-unknown-unknown,wasm32-wasi \
830de2ed 310 library/std
8d2dc69d 311endif
5861ebac 312ifeq (true,$(BUILD_DOCS))
04c12273 313 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
807a241f 314 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS) cargo # document cargo APIs
04c12273
XL
315endif
316
3a774f0f 317TEST_LOG = debian/rustc-tests.log
356c70ca
XL
318# This is advertised as "5 tests failed" in README.Debian because our counting
319# method is imprecise and in practise we count some failures twice.
165f40f0
FG
320# temporarily bumped from 8 to 10 to account for test output changes depending
321# on build path length, bump down again once 1.78 is imported
322FAILURES_ALLOWED = 10
94a85be8 323ifneq (,$(filter $(DEB_BUILD_ARCH), armhf))
165f40f0
FG
324# temporarily bumped from 12 to 15, see above
325 FAILURES_ALLOWED = 15
fa6232de 326endif
b4b364c0 327ifneq (,$(filter $(DEB_BUILD_ARCH), armel mips mips64el))
15f51d41 328 FAILURES_ALLOWED = 24
ab330327 329endif
b4b364c0
FG
330# workaround broken gdb 13.1 - revert to 24 once fixed
331# #1031946 / #1032785
332ifneq (,$(filter $(DEB_BUILD_ARCH), mipsel))
e2642af0 333 FAILURES_ALLOWED = 25
b4b364c0 334endif
0ceea14c 335ifneq (,$(filter $(DEB_BUILD_ARCH), ppc64 s390x))
fdd627af
XL
336 FAILURES_ALLOWED = 40
337endif
6f423e6e 338ifneq (,$(filter $(DEB_BUILD_ARCH), powerpc powerpcspe riscv64 sparc64 x32))
617a87c6 339 FAILURES_ALLOWED = 180
734d072d 340endif
01620f26 341FAILED_TESTS = grep "FAILED\|^command did not execute successfully" $(TEST_LOG) | grep -v '^test result: FAILED' | grep -v 'FAILED (allowed)'
beb2e50b
XL
342# ignore debuginfo failures on armhf due to regression in GDB 11.2
343# https://sourceware.org/bugzilla/show_bug.cgi?id=29272
344ifneq (,$(filter $(DEB_BUILD_ARCH), armhf))
ec5a277d 345 FAILED_TESTS += | grep -v '^test \[debuginfo-gdb\] src/test/debuginfo/'
beb2e50b 346endif
7958f3db 347override_dh_auto_test-arch:
91d3be64 348 # ensure that rustc_llvm is actually dynamically linked to libLLVM
347f6206
XL
349 set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \
350 while read x; do \
351 stat -c '%s %n' "$$x"; \
352 objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \
353 test "$$(stat -c %s "$$x")" -lt 6000000; \
354 done
68e7eb97 355ifeq (, $(filter nocheck,$(DEB_BUILD_PROFILES)))
7958f3db 356ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
8978aae4 357 { $(RUSTBUILD_TEST) $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS); echo $$?; } | tee -a $(TEST_LOG)
91d3be64 358 # test that the log has at least 1 pass, to prevent e.g. #57709
bbceb41b 359 grep -l "^test .* \.\.\. ok$$" $(TEST_LOG)
2c22371f
XL
360 echo "==== Debian rustc test report ===="; \
361 echo "Specific test failures:"; \
3a774f0f 362 $(FAILED_TESTS); \
873d1fa5 363 num_failures=$$($(FAILED_TESTS) | wc -l); \
2c22371f
XL
364 exit_code=$$(tail -n1 $(TEST_LOG)); \
365 echo "Summary: exit code $$exit_code, counted $$num_failures tests failed."; \
366 echo -n "$(FAILURES_ALLOWED) maximum allowed. "; \
367 if test "$$num_failures" -eq 0 -a "$$exit_code" -ne 0; then \
368 echo "Aborting just in case, because we missed counting some test failures."; \
6404b712 369 echo "This could happen if we failed to build the tests, or if the testsuite runner is buggy."; \
2c22371f
XL
370 false; \
371 elif test "$$num_failures" -le $(FAILURES_ALLOWED); then \
3a774f0f
XL
372 echo "Continuing..."; \
373 else \
374 echo "Aborting the build."; \
375 echo "Check the logs further above for details."; \
376 false; \
377 fi
0d3674eb
XL
378# don't continue if RUSTBUILD_TEST_FLAGS is non-empty
379 test -z "$(RUSTBUILD_TEST_FLAGS)"
27da05fd 380# don't run windows tests yet
e408bc2c 381endif
68e7eb97 382endif
becfe001 383
04c12273 384override_dh_auto_test-indep:
68e7eb97 385ifeq (, $(filter nocheck,$(DEB_BUILD_PROFILES)))
7958f3db 386ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
8d2dc69d 387ifeq (true,$(BUILD_WASM))
8978aae4 388 # Ignore failures in these tests, but run them so we see what it's like
005427f4 389 -PATH=$(CURDIR)/debian/bin:$(PATH) $(RUSTBUILD_TEST) $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS) \
910f03de
XL
390 --host $(DEB_BUILD_RUST_TYPE) \
391 --target wasm32-unknown-unknown,wasm32-wasi \
830de2ed 392 library/std
8d2dc69d 393endif
aa14b88a 394ifeq (true,$(BUILD_DOCS))
8978aae4
XL
395 # Run all rules that test the docs, i.e. that depend on default:doc
396 $(RUSTBUILD_TEST) $(RUSTBUILD_FLAGS) src/tools/linkchecker
7958f3db 397endif
aa14b88a 398 test -z "$(RUSTBUILD_TEST_FLAGS)"
7958f3db 399endif
68e7eb97 400endif
04c12273 401
bf52bd52
XL
402run_rustbuild:
403 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) $(X_CMD) $(RUSTBUILD_FLAGS) $(X_FLAGS)
404
110dae6c
XL
405override_dh_prep:
406 dh_prep
407 $(RM) -f debian/dh_auto_install.stamp
408
3bdf427a 409debian/dh_auto_install.stamp:
6a9e99e9 410 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS)
525ff0f9
AL
411
412 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
413 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
6fce0a99 414
1261b4b3 415 # Replace duplicated compile-time/run-time dylibs with symlinks
525ff0f9
AL
416 @set -e; \
417 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
418 name=$${f##*/}; \
419 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
420 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
421 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
422 fi; \
1261b4b3
AL
423 done
424
a3c87cc8 425 # Remove Cargo made package cache
3f4b7b35 426 rm -vf $(CURDIR)/debian/cargo/.package-cache
a3c87cc8 427
3bdf427a
XL
428 touch "$@"
429
430override_dh_auto_install-arch: debian/dh_auto_install.stamp
27da05fd
XL
431ifeq (true,$(BUILD_WINDOWS))
432 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
433 --host $(DEB_BUILD_RUST_TYPE) \
434 --target $(WINDOWS_ARCH)-pc-windows-gnu \
830de2ed 435 library/std
27da05fd 436endif
4aaf3ea8 437 # Remove Cargo made package cache
c9c1ae93 438 rm -vf $(CURDIR)/debian/cargo/.package-cache
4aaf3ea8 439
27da05fd 440
3bdf427a 441override_dh_auto_install-indep: debian/dh_auto_install.stamp
8d2dc69d 442ifeq (true,$(BUILD_WASM))
453f6ddc 443 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) \
910f03de
XL
444 --host $(DEB_BUILD_RUST_TYPE) \
445 --target wasm32-unknown-unknown,wasm32-wasi \
830de2ed 446 library/std
8d2dc69d 447endif
5861ebac 448ifeq (true,$(BUILD_DOCS))
807a241f 449 # Install Cargo docs
450 install -d $(DEB_DESTDIR)/usr/share/doc/cargo
6686fd92 451 cp -r $(CURDIR)/build/$(DEB_BUILD_RUST_TYPE)/compiler-doc $(DEB_DESTDIR)/usr/share/doc/cargo/reference
6fce0a99
SL
452 # Brute force to remove privacy-breach-logo lintian warning.
453 # We could have updated the upstream sources but it would complexify
454 # the rebase
b556761e 455 @set -e; \
450ac6ae 456 find $(DEB_DESTDIR)/usr/share/doc/*/html -iname '*.html' | \
1add0b94 457 while read file; do \
b556761e 458 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
450ac6ae
XL
459 sed -i \
460 -e "s,https://\(doc\|www\).rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
b8b69291 461 -e 's,<img src="https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test%20(bors)/badge.svg[^"]*" alt="\([^"]*\)" />,<span class="deb-privacy-replace--github.com-badge">\1</span>,g' \
450ac6ae 462 -e 's,<img src="https://img.shields.io/[^"]*" alt="\([^"]*\)" />,<span class="deb-privacy-replace--shields-io">\1</span>,g' "$$file"; \
1add0b94 463 done
b125a683 464 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
6686fd92
FG
465
466 # mv cargo book to cargo-docs
467 mv $(DEB_DESTDIR)/usr/share/doc/rust/html/cargo $(DEB_DESTDIR)/usr/share/doc/cargo/book
b125a683 468endif
4aaf3ea8 469 # Remove Cargo made package cache
3f4b7b35 470 rm -vf $(CURDIR)/debian/cargo/.package-cache
4aaf3ea8 471
b125a683 472
eede8545 473override_dh_install-indep:
6fce0a99 474 dh_install
b5dfb68c 475 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rustc-$(RUST_LONG_VERSION)/%)
f40dfcc0 476 # Get rid of lintian warnings
b5dfb68c 477 find debian/rust-src/usr/src/rustc-$(RUST_LONG_VERSION) \
f40dfcc0
XL
478 \( -name .gitignore \
479 -o -name 'LICENSE*' \
480 -o -name 'LICENCE' \
481 -o -name 'license' \
482 -o -name 'COPYING*' \
b6d33132 483 -o -name '.eslintrc.js' \
f40dfcc0 484 \) -delete
8d3e3cd2 485 # Remove files that autoload remote resources, caught by lintian
f56f18fe
XL
486 $(RM) -rf debian/rust-src/usr/src/rustc-*/vendor/cssparser/docs/*.html
487 $(RM) -rf debian/rust-src/usr/src/rustc-*/vendor/kuchiki/docs/*.html
488 $(RM) -rf debian/rust-src/usr/src/rustc-*/vendor/url/docs/*.html
489 $(RM) -rf debian/rust-src/usr/src/rustc-*/vendor/xz2/.gitmodules
1c8ac2b0 490
bc0aa84e
AL
491override_dh_installchangelogs:
492 dh_installchangelogs RELEASES.md
493
494override_dh_installdocs:
495 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
496
eef1f4e3
AL
497override_dh_compress:
498 dh_compress -X.woff
499
b676ddf6
XL
500# The below override is disabled on advice from #debian-devel, because:
501# - only shared libs get the "split dbgsym package" treatment by dh_strip;
502# static libs simply get their debuginfo discarded
503# - strip(1) sometimes breaks wasm libs
504#
505#override_dh_strip:
506# # Work around #35733, #468333
507# find debian/libstd-rust-dev*/ -name '*.rlib' -execdir mv '{}' '{}.a' \;
508# # This is expected to print out lots of "File format unrecognized" warnings about
509# # rust.metadata.bin and *.deflate but the .o files inside the rlibs should be stripped
510# # Some files are still omitted because of #875780 however.
511# dh_strip -v
512# find debian/libstd-rust-dev*/ -name '*.rlib.a' -execdir sh -c 'mv "$$1" "$${1%.a}"' - '{}' \;
d2456730 513
f6fae01b
XL
514override_dh_dwz:
515 # otherwise rustc gets an empty multifile which lintian errors on, causing
516 # FTP auto-reject. this is a work-around, the lintian bug is #955752
517 dh_dwz --no-dwz-multifile
518
525ff0f9
AL
519override_dh_makeshlibs:
520 dh_makeshlibs -V
521
522 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
523 # structure, so we have to do this ourselves.
a508e13b 524 mkdir -p debian/$(LIBSTD_PKG)/DEBIAN
33766656 525 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
525ff0f9
AL
526 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
527 while read name version; do \
528 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
529 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
525ff0f9
AL
530
531override_dh_shlibdeps:
532 dh_shlibdeps -- -x$(LIBSTD_PKG)
427dce5b
XL
533
534QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
75be2bb3 535source_orig-stage0:
16dfb283
XL
536 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
537 $(MAKE) -f debian/rules clean
75be2bb3 538 debian/make_orig-stage0_tarball.sh
c9e6dc3f 539 $(MAKE) -f debian/rules clean
16dfb283
XL
540 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
541 rm -rf .pc
15ab0b38 542
0a1981fb
XL
543get_beta_version = \
544 u="$(DEB_VERSION_UPSTREAM)"; \
545 if [ "$$u" != "$${u%~beta.*+dfsg*}" ]; then \
546 newver=$(shell echo $(RUST_VERSION) | perl -lpe 's/(\d+)\.(\d+)/$$1 . "." . ($$2)/e'); \
547 else \
15ab0b38 548 newver=$(shell echo $(RUST_VERSION) | perl -lpe 's/(\d+)\.(\d+)/$$1 . "." . ($$2+1)/e'); \
0a1981fb
XL
549 fi
550
551debian/watch-beta: debian/watch-beta.in debian/rules
552 set -e; $(get_beta_version); \
15ab0b38
XL
553 m4 -DOLDVER="$$oldver" -DNEWVER="$$newver.0" "$<" > "$@"
554
555source_orig-beta: debian/watch-beta
d377cbf5 556 uscan $(USCAN_OPTS) $(if $(USCAN_DESTDIR),--destdir=$(USCAN_DESTDIR),) --verbose --watchfile "$<"
0a1981fb 557 set -e; $(get_beta_version); \
d377cbf5
XL
558 bd="$(if $(USCAN_DESTDIR),$(USCAN_DESTDIR),..)"; \
559 tar xf $$bd/rustc-$$newver.0-beta.999-src.tar.xz rustc-beta-src/version; \
0a1981fb 560 bv="$$(sed -re 's/[0-9]+.[0-9]+.[0-9]+-beta.([0-9]+) \(.*\)/\1/g' rustc-beta-src/version)"; \
d377cbf5 561 bash -c 'shopt -s nullglob; for i in '"$$bd"'/rustc*beta.999*; do mv $$i $${i/beta.999/beta.'"$$bv"'}; done'; \
3af75deb
XL
562 rm -f rustc-beta-src/version; \
563 rmdir -p rustc-beta-src; \
d377cbf5 564 echo "prepared rustc $$newver.0~beta.$$bv in $$bd"