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