]> git.proxmox.com Git - rustc.git/blame - debian/rules
Referesh patches and remove obsolete ones
[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
13
7d40d3e1 14include /usr/share/dpkg/buildflags.mk
4888e768 15# TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml
9197bf09 16RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
7d40d3e1 17export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
9197bf09
XL
18# set remap-path-prefix for reproducible builds; TODO: remove "if" after 1.20
19ifeq (0,$(shell dpkg --compare-versions "$$(rustc --version --verbose | sed -ne 's/^release: //p')" '>=' 1.19.0; echo $$?))
20RUSTFLAGS += -Zremap-path-prefix-from=$(CURDIR) -Zremap-path-prefix-to=/usr/src/rustc-$(RUST_LONG_VERSION)
21export RUSTC_BOOTSTRAP = 1
22endif
b59979d9 23
525ff0f9
AL
24# Defines DEB_*_RUST_TYPE triples
25include debian/architecture.mk
693daed7 26export DEB_HOST_RUST_TYPE
525ff0f9 27
be771b38
LB
28# Uncomment this to turn on verbose mode.
29#export DH_VERBOSE=1
30
c2a1d9e3
AL
31# src/rt/miniz.c (incorrectly) triggers -Wmisleading-indentation with
32# gcc-6. See bug #811573.
33CFLAGS += -Wno-misleading-indentation
34
d4357a26 35# Release type (one of beta, stable or nightly)
0f9154de 36RELEASE_CHANNEL := stable
6935ded2
XL
37# See also ./build-preview-dsc.sh for a script that builds a beta/nightly .dsc
38# out of this packaging. Furthermore, if the build breaks after importing a new
39# upstream stable release, check the do_temporary_fixup function in that file
40# to see if we already know what fix to make.
d4357a26 41
8354de7a 42DEB_DESTDIR := $(CURDIR)/debian/tmp
525ff0f9 43
01dc6ef4
XL
44# These are the normal build flags. Upstream is moving to debian/config.toml
45# but at the current version not all of these flags are available in that file.
3613a4e9
XL
46# Certain flags also need to be kept here *as well as* debian/config.toml.in
47# because of https://github.com/rust-lang/rust/issues/43295
0ace110a 48DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr --release-channel=$(RELEASE_CHANNEL) --disable-debuginfo-only-std
be771b38 49
525ff0f9 50# Use system LLVM (comment out to use vendored LLVM)
666f0397
XL
51LLVM_VERSION = 4.0
52OLD_LLVM_VERSION = 3.9
53DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-$(LLVM_VERSION)
8e396fda 54RUSTBUILD = RUST_BACKTRACE=1 ./x.py
3613a4e9 55RUSTBUILD_FLAGS = --config debian/config.toml -v --on-fail env
f1b4ffd3
XL
56# TODO: This should simply be "$(RUSTBUILD) test" but unfortunately this causes
57# an insane blow up in the time it takes to run tests. See upstream #37477 for
58# details. Upstream worked around it in #38984 but in Debian we can't take
59# advantage of that work-around, because we want as much debuginfo as possible
60# (so we set debuginfo-lines = true, debuginfo-only-std = false) so we have to
61# work around it instead by disabling backtrace when running tests.
62RUSTBUILD_TEST = ./x.py test
0d3674eb
XL
63# To run a specific test, run something like:
64# $ debian/rules override_dh_auto_test-arch \
65# RUSTBUILD_TEST_FLAGS="src/test/run-make --test-args extern-fn-struct"
66# See src/bootstrap/README.md for more options.
67RUSTBUILD_TEST_FLAGS =
1c8ac2b0 68
25f1c2fe
XL
69update-version:
70 oldver=$(shell $(SED_RUSTC_BUILDDEP) | sed -ne 's/.*(<= \(.*\)).*/\1/gp' | $(SED_VERSION_SHORT)); \
71 newver=$(RUST_VERSION); \
72 if [ $$oldver != $$newver ]; then debian/update-version.sh $$oldver $$newver; fi
73
427dce5b
XL
74# Below we detect how we're supposed to bootstrap the stage0 compiler. See
75# README.Debian for more details of the cases described below.
76#
427dce5b 77PRECONFIGURE_CHECK = :
75be2bb3 78HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
571f0d20
MK
79# allow not using the binary tarball although it exists
80#ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
81# HAVE_BINARY_TARBALL := 0
82#endif
83ifeq (0,$(HAVE_BINARY_TARBALL))
16dfb283
XL
84 # Case A (Building from source): the extracted source tree does not include
85 # a bootstrapping tarball for the current architecture e.g. because the
86 # distro already has a rustc for this arch, or the uploader expects that
87 # this requirement be fulfilled in some other way.
427dce5b
XL
88 #
89 # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
90 # In this case, we use the distro's rustc - either the previous or current version.
91 ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
92 DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
93 endif
94 #
95 # Case A-2: the builder selected the "dlstage0" build profile.
75be2bb3 96 # In this case, the rust build scripts will download a stage0 into stage0/ and use that.
b9a40c91 97 # We don't need to do anything specific in this build file, so this case is empty.
427dce5b 98else
16dfb283
XL
99 # Case B (Bootstrapping a new distro): the extracted source tree does
100 # include a bootstrapping tarball for the current architecture; see the
75be2bb3 101 # `source_orig-stage0` target below on how to build this.
427dce5b
XL
102 #
103 # In this case, we'll bootstrap from the stage0 given in that tarball.
104 # To ensure the uploader of the .dsc didn't make a mistake, we first check
16dfb283 105 # that rustc isn't a Build-Depends for the current architecture.
25f1c2fe
XL
106 ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
107 ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
75be2bb3 108 PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \
16dfb283
XL
109 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
110 endif
427dce5b 111 endif
1c8ac2b0
SL
112endif
113
114BUILD_DOCS = 1
120b4d47 115ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
525ff0f9 116 DEB_CONFIGURE_FLAGS += --disable-docs
2e97839d 117 BUILD_DOCS =
1c8ac2b0
SL
118endif
119
120ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
525ff0f9 121 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
1c8ac2b0
SL
122endif
123
35329365
XL
124# Build products or non-source files in src/, that shouldn't go in rust-src
125SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
126 src/bootstrap/bootstrap.pyc \
35329365 127 src/etc/__pycache__/
1c8ac2b0 128
170f9149
XL
129# Workaround for linux #865549
130ifeq (0,$(shell test $$(uname -s) = "Linux" -a $$(getconf PAGESIZE) -gt 4096; echo $$?))
131 SYSTEM_WORKAROUNDS += ulimit -s $$(expr $$(getconf PAGESIZE) / 1024 '*' 256 + 8192);
132endif
133
be771b38 134%:
170f9149 135 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
be771b38 136
04c12273
XL
137.PHONY: build
138build:
170f9149 139 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
04c12273 140
de1de54b
XL
141override_dh_clean:
142 dh_clean -Xsrc/vendor/bitflags/Cargo.toml.orig
143
b1076f25
XL
144debian/configure-upstream: debian/config.toml debian/rules
145 rm -f "$@"
146 echo '#!/bin/sh' >> "$@"
6a9e99e9 147 echo '# This script can be used to configure a mostly-clean upstream checkout' >> "$@"
b1076f25
XL
148 echo '# in case you need to test any differences between it and Debian' >> "$@"
149 echo 'set -e' >> "$@"
150 echo 'test -f ./configure' >> "$@"
151 echo 'cat > config.toml <<EOF' >> "$@"
152 cat debian/config.toml >> "$@"
153 echo 'EOF' >> "$@"
154 echo "./configure $(DEB_CONFIGURE_FLAGS)" >> "$@"
155 chmod +x "$@"
156
01dc6ef4
XL
157debian/config.toml: debian/config.toml.in
158 m4 -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
159 -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
160 -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
161 -DRELEASE_CHANNEL="$(RELEASE_CHANNEL)" \
666f0397 162 -DLLVM_VERSION="$(LLVM_VERSION)" \
01dc6ef4
XL
163 "$<" > "$@"
164
b5dfb68c
XL
165debian/rust-src.%: debian/rust-src.%.in
166 m4 -DRUST_LONG_VERSION="$(RUST_LONG_VERSION)" \
167 "$<" > "$@"
168
01dc6ef4 169override_dh_auto_configure: debian/config.toml
5617e1bd 170 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
666f0397 171 ! grep --color=always -i 'll...\?$(subst .,\.,$(OLD_LLVM_VERSION))' --exclude=changelog -R debian
427dce5b 172 $(PRECONFIGURE_CHECK)
75be2bb3 173 if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi
3281855a
XL
174 # work around #842634
175 if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \
ed6f7eed 176 debian/ensure-patch -N debian/patches/d-host-duplicates.patch; fi
6b0d97fc
XL
177 # We patched mdbook so have to rm the checksums
178 debian/empty-cargo-checksum.py src/vendor/mdbook/.cargo-checksum.json
179 # Unfortunately upstream uses a duplicate copy of libbacktrace and wants to
180 # compile it again for rust-installer, see #43449
181 ln -rsf src/libbacktrace -t src/vendor/backtrace-sys/src/
182 debian/empty-cargo-checksum.py src/vendor/backtrace-sys/.cargo-checksum.json
183 # Link against system liblzma, see https://github.com/alexcrichton/xz2-rs/issues/16
184 echo 'fn main() { println!("cargo:rustc-link-lib=lzma"); }' > src/vendor/lzma-sys/build.rs
185 debian/empty-cargo-checksum.py src/vendor/lzma-sys/.cargo-checksum.json
30248d38
XL
186 # We excluded some embedded libraries in d/copyright
187 debian/empty-cargo-checksum.py src/vendor/dbghelp-sys/.cargo-checksum.json
bf621149
XL
188 # TODO: work-around for slightly buggy prune-unused-deps, can rm in 1.20.0
189 rmdir src/vendor/* 2>/dev/null || true
6b0d97fc 190 # Do the actual configure
4888e768 191 PATH="$$PWD/debian/bin:$$PATH" \
525ff0f9 192 ./configure $(DEB_CONFIGURE_FLAGS)
1c8ac2b0 193
11c430be 194override_dh_auto_clean:
f40dfcc0 195 $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile
b5dfb68c 196 $(RM) -rf $(SRC_CLEAN) debian/config.toml debian/rust-src.install debian/rust-src.links
11c430be 197
ea192313
XL
198# upstream bundles this in the source, but in Debian we rebuild everything yo
199generate-sources:
200 $(MAKE) -C src/rt/hoedown src/html_blocks.c
1c8ac2b0 201
ea192313 202override_dh_auto_build-arch: generate-sources
04c12273 203 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
ea192313 204
e408bc2c
XL
205# note: this is only for buildds that want to do a separate arch:all build;
206# there is no point running this yourself "to save time" since it implicitly
207# depends on build-arch anyways.
ea192313 208override_dh_auto_build-indep: generate-sources
e408bc2c 209ifneq (,$(BUILD_DOCS))
1fd63ebe
XL
210# Rust has a weird way of configuring whether to build docs or not
211 sed -i -e 's/^docs = false/docs = true/' debian/config.toml
04c12273
XL
212 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
213endif
214
7958f3db
XL
215RUN_TESTS = \
216 if $(1); then \
04c12273 217 : ; \
6472c211 218 elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
04c12273 219 false; \
6472c211
XL
220 elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \
221 false ; \
04c12273
XL
222 else \
223 echo "====================================================="; \
224 echo "WARNING: Ignoring test failures in the rust testsuite"; \
225 echo "====================================================="; \
226 fi
7958f3db
XL
227
228override_dh_auto_test-arch:
347f6206
XL
229# ensure that rustc_llvm is actually dynamically linked to libLLVM
230 set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \
231 while read x; do \
232 stat -c '%s %n' "$$x"; \
233 objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \
234 test "$$(stat -c %s "$$x")" -lt 6000000; \
235 done
68e7eb97 236ifeq (, $(filter nocheck,$(DEB_BUILD_PROFILES)))
7958f3db 237ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
f1b4ffd3 238 $(call RUN_TESTS,$(RUSTBUILD_TEST) --no-fail-fast $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS))
0d3674eb
XL
239# don't continue if RUSTBUILD_TEST_FLAGS is non-empty
240 test -z "$(RUSTBUILD_TEST_FLAGS)"
e408bc2c 241endif
68e7eb97 242endif
becfe001 243
04c12273 244override_dh_auto_test-indep:
7958f3db 245ifneq (,$(BUILD_DOCS))
68e7eb97 246ifeq (, $(filter nocheck,$(DEB_BUILD_PROFILES)))
7958f3db
XL
247ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
248 # Run all rules that test the docs, i.e. in step.rs that depend on default:doc
f1b4ffd3 249 $(call RUN_TESTS,$(RUSTBUILD_TEST) --no-fail-fast src/tools/linkchecker $(RUSTBUILD_FLAGS))
7958f3db
XL
250endif
251endif
68e7eb97 252endif
04c12273 253
23d2674b 254override_dh_auto_install:
6a9e99e9 255 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS)
525ff0f9
AL
256
257 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
258 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
6fce0a99 259
1261b4b3 260 # Replace duplicated compile-time/run-time dylibs with symlinks
525ff0f9
AL
261 @set -e; \
262 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
263 name=$${f##*/}; \
264 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
265 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
266 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
267 fi; \
1261b4b3
AL
268 done
269
525ff0f9 270ifneq (,$(BUILD_DOCS))
6fce0a99
SL
271 # Brute force to remove privacy-breach-logo lintian warning.
272 # We could have updated the upstream sources but it would complexify
273 # the rebase
b556761e
AL
274 @set -e; \
275 find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \
1add0b94 276 while read file; do \
b556761e 277 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
92f6ea48 278 sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
87a30969 279 -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
1add0b94 280 done
b125a683
MO
281 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
282endif
283
cf9ecdde 284override_dh_install-arch:
6fce0a99 285 dh_install
525ff0f9
AL
286 dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
287
b5dfb68c 288override_dh_install-indep: debian/rust-src.install debian/rust-src.links
a0022868 289 dh_install
525ff0f9
AL
290 chmod -x \
291 debian/rust-gdb/usr/share/rust-gdb/*.py \
292 debian/rust-lldb/usr/share/rust-lldb/*.py
b5dfb68c 293 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rustc-$(RUST_LONG_VERSION)/%)
f40dfcc0 294 # Get rid of lintian warnings
b5dfb68c 295 find debian/rust-src/usr/src/rustc-$(RUST_LONG_VERSION) \
f40dfcc0
XL
296 \( -name .gitignore \
297 -o -name 'LICENSE*' \
298 -o -name 'LICENCE' \
299 -o -name 'license' \
300 -o -name 'COPYING*' \
301 \) -delete
b5dfb68c 302 cd debian/rust-src/usr/src/rustc-$(RUST_LONG_VERSION) && chmod -x \
f40dfcc0 303 src/etc/gdb_rust_pretty_printing.py \
f40dfcc0 304 src/compiler-rt/test/builtins/Unit/ppc/test
1c8ac2b0 305
bc0aa84e
AL
306override_dh_installchangelogs:
307 dh_installchangelogs RELEASES.md
308
309override_dh_installdocs:
310 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
311
eef1f4e3
AL
312override_dh_compress:
313 dh_compress -X.woff
314
d2456730
XL
315override_dh_strip:
316 # Work around #35733, #468333
317 find debian/libstd-rust-dev/ -name '*.rlib' -execdir mv '{}' '{}.a' \;
318 # This is expected to print out lots of "File format unrecognized" warnings about
319 # rust.metadata.bin and *.deflate but the .o files inside the rlibs should be stripped
320 # Some files are still omitted because of #875780 however.
321 dh_strip -v
322 find debian/libstd-rust-dev/ -name '*.rlib.a' -execdir sh -c 'mv "$$1" "$${1%.a}"' - '{}' \;
323
525ff0f9
AL
324override_dh_makeshlibs:
325 dh_makeshlibs -V
326
327 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
328 # structure, so we have to do this ourselves.
329 install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
33766656 330 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
525ff0f9
AL
331 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
332 while read name version; do \
333 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
334 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
335 chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
336 chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
337
338override_dh_shlibdeps:
339 dh_shlibdeps -- -x$(LIBSTD_PKG)
427dce5b
XL
340
341QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
75be2bb3 342source_orig-stage0:
16dfb283
XL
343 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
344 $(MAKE) -f debian/rules clean
75be2bb3 345 debian/make_orig-stage0_tarball.sh
16dfb283
XL
346 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
347 rm -rf .pc