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