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