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