]> git.proxmox.com Git - rustc.git/blame - debian/rules
Add a strong check that rustc_llvm is actually dynamically-linked
[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
7d40d3e1 7include /usr/share/dpkg/buildflags.mk
4888e768 8# TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml
a1140187 9RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
7d40d3e1 10export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
b59979d9 11
525ff0f9
AL
12# Defines DEB_*_RUST_TYPE triples
13include debian/architecture.mk
693daed7 14export DEB_HOST_RUST_TYPE
525ff0f9 15
be771b38
LB
16# Uncomment this to turn on verbose mode.
17#export DH_VERBOSE=1
18
c2a1d9e3
AL
19# src/rt/miniz.c (incorrectly) triggers -Wmisleading-indentation with
20# gcc-6. See bug #811573.
21CFLAGS += -Wno-misleading-indentation
22
d4357a26 23# Release type (one of beta, stable or nightly)
0f9154de 24RELEASE_CHANNEL := stable
6935ded2
XL
25# See also ./build-preview-dsc.sh for a script that builds a beta/nightly .dsc
26# out of this packaging. Furthermore, if the build breaks after importing a new
27# upstream stable release, check the do_temporary_fixup function in that file
28# to see if we already know what fix to make.
d4357a26 29
8354de7a 30DEB_DESTDIR := $(CURDIR)/debian/tmp
525ff0f9 31
25f1c2fe
XL
32SED_VERSION_SHORT := sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/'
33RUST_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | $(SED_VERSION_SHORT))
4888e768 34RUST_LONG_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -re 's/([^+]+).*/\1/')
888747f5 35LIBSTD_PKG := libstd-rust-$(RUST_VERSION)
25f1c2fe 36# Sed expression that matches the "rustc" we have in our Build-Depends field
66deafc1 37SED_RUSTC_BUILDDEP := sed -ne "/^Build-Depends:/,/^[^[:space:]\#]/{/^ *rustc:native .*,/p}" debian/control
02b74708 38
01dc6ef4
XL
39# These are the normal build flags. Upstream is moving to debian/config.toml
40# but at the current version not all of these flags are available in that file.
4fd68f78 41DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr
be771b38 42
525ff0f9 43# Use system LLVM (comment out to use vendored LLVM)
5617e1bd 44OLD_LLVM_VERSION = 3.8
893bf96c 45DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-3.9
04c12273 46RUSTBUILD = ./x.py
01dc6ef4 47RUSTBUILD_FLAGS = --config debian/config.toml -v
1c8ac2b0 48
25f1c2fe
XL
49update-version:
50 oldver=$(shell $(SED_RUSTC_BUILDDEP) | sed -ne 's/.*(<= \(.*\)).*/\1/gp' | $(SED_VERSION_SHORT)); \
51 newver=$(RUST_VERSION); \
52 if [ $$oldver != $$newver ]; then debian/update-version.sh $$oldver $$newver; fi
53
427dce5b
XL
54# Below we detect how we're supposed to bootstrap the stage0 compiler. See
55# README.Debian for more details of the cases described below.
56#
427dce5b 57PRECONFIGURE_CHECK = :
75be2bb3 58HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
571f0d20
MK
59# allow not using the binary tarball although it exists
60#ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
61# HAVE_BINARY_TARBALL := 0
62#endif
63ifeq (0,$(HAVE_BINARY_TARBALL))
16dfb283
XL
64 # Case A (Building from source): the extracted source tree does not include
65 # a bootstrapping tarball for the current architecture e.g. because the
66 # distro already has a rustc for this arch, or the uploader expects that
67 # this requirement be fulfilled in some other way.
427dce5b
XL
68 #
69 # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
70 # In this case, we use the distro's rustc - either the previous or current version.
71 ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
72 DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
73 endif
74 #
75 # Case A-2: the builder selected the "dlstage0" build profile.
75be2bb3 76 # In this case, the rust build scripts will download a stage0 into stage0/ and use that.
b9a40c91 77 # We don't need to do anything specific in this build file, so this case is empty.
427dce5b 78else
16dfb283
XL
79 # Case B (Bootstrapping a new distro): the extracted source tree does
80 # include a bootstrapping tarball for the current architecture; see the
75be2bb3 81 # `source_orig-stage0` target below on how to build this.
427dce5b
XL
82 #
83 # In this case, we'll bootstrap from the stage0 given in that tarball.
84 # To ensure the uploader of the .dsc didn't make a mistake, we first check
16dfb283 85 # that rustc isn't a Build-Depends for the current architecture.
25f1c2fe
XL
86 ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
87 ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
75be2bb3 88 PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \
16dfb283
XL
89 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
90 endif
427dce5b 91 endif
1c8ac2b0
SL
92endif
93
94BUILD_DOCS = 1
120b4d47 95ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
525ff0f9 96 DEB_CONFIGURE_FLAGS += --disable-docs
2e97839d 97 BUILD_DOCS =
1c8ac2b0
SL
98endif
99
100ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
525ff0f9 101 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
1c8ac2b0
SL
102endif
103
35329365
XL
104# Build products or non-source files in src/, that shouldn't go in rust-src
105SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
106 src/bootstrap/bootstrap.pyc \
35329365 107 src/etc/__pycache__/
1c8ac2b0 108
170f9149
XL
109# Workaround for linux #865549
110ifeq (0,$(shell test $$(uname -s) = "Linux" -a $$(getconf PAGESIZE) -gt 4096; echo $$?))
111 SYSTEM_WORKAROUNDS += ulimit -s $$(expr $$(getconf PAGESIZE) / 1024 '*' 256 + 8192);
112endif
113
be771b38 114%:
170f9149 115 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
be771b38 116
04c12273
XL
117.PHONY: build
118build:
170f9149 119 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
04c12273 120
01dc6ef4
XL
121debian/config.toml: debian/config.toml.in
122 m4 -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
123 -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
124 -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
125 -DRELEASE_CHANNEL="$(RELEASE_CHANNEL)" \
126 "$<" > "$@"
127
128override_dh_auto_configure: debian/config.toml
5617e1bd 129 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
01dc6ef4 130 ! grep --color=always -i 'll...?$(OLD_LLVM_VERSION)' --exclude=changelog -R debian
427dce5b 131 $(PRECONFIGURE_CHECK)
75be2bb3 132 if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi
3281855a
XL
133 # work around #842634
134 if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \
ed6f7eed 135 debian/ensure-patch -N debian/patches/d-host-duplicates.patch; fi
4888e768 136 PATH="$$PWD/debian/bin:$$PATH" \
525ff0f9 137 ./configure $(DEB_CONFIGURE_FLAGS)
1c8ac2b0 138
11c430be 139override_dh_auto_clean:
f40dfcc0 140 $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile
01dc6ef4 141 $(RM) -rf $(SRC_CLEAN) debian/config.toml
11c430be 142
ea192313
XL
143# upstream bundles this in the source, but in Debian we rebuild everything yo
144generate-sources:
145 $(MAKE) -C src/rt/hoedown src/html_blocks.c
1c8ac2b0 146
ea192313 147override_dh_auto_build-arch: generate-sources
04c12273 148 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
ea192313 149
e408bc2c
XL
150# note: this is only for buildds that want to do a separate arch:all build;
151# there is no point running this yourself "to save time" since it implicitly
152# depends on build-arch anyways.
ea192313 153override_dh_auto_build-indep: generate-sources
e408bc2c 154ifneq (,$(BUILD_DOCS))
1fd63ebe
XL
155# Rust has a weird way of configuring whether to build docs or not
156 sed -i -e 's/^docs = false/docs = true/' debian/config.toml
04c12273
XL
157 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
158endif
159
7958f3db
XL
160RUN_TESTS = \
161 if $(1); then \
04c12273 162 : ; \
6472c211 163 elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
04c12273 164 false; \
6472c211
XL
165 elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \
166 false ; \
04c12273
XL
167 else \
168 echo "====================================================="; \
169 echo "WARNING: Ignoring test failures in the rust testsuite"; \
170 echo "====================================================="; \
171 fi
7958f3db
XL
172
173override_dh_auto_test-arch:
347f6206
XL
174# ensure that rustc_llvm is actually dynamically linked to libLLVM
175 set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \
176 while read x; do \
177 stat -c '%s %n' "$$x"; \
178 objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \
179 test "$$(stat -c %s "$$x")" -lt 6000000; \
180 done
7958f3db
XL
181ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
182 $(call RUN_TESTS,RUST_BACKTRACE=1 $(RUSTBUILD) test $(RUSTBUILD_FLAGS))
e408bc2c 183endif
becfe001 184
04c12273 185override_dh_auto_test-indep:
7958f3db
XL
186ifneq (,$(BUILD_DOCS))
187ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
188 # Run all rules that test the docs, i.e. in step.rs that depend on default:doc
189 $(call RUN_TESTS,RUST_BACKTRACE=1 $(RUSTBUILD) test src/tools/linkchecker $(RUSTBUILD_FLAGS))
190endif
191endif
04c12273 192
23d2674b 193override_dh_auto_install:
04c12273 194 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) dist $(RUSTBUILD_FLAGS) --install
525ff0f9
AL
195
196 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
197 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
6fce0a99 198
1261b4b3 199 # Replace duplicated compile-time/run-time dylibs with symlinks
525ff0f9
AL
200 @set -e; \
201 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
202 name=$${f##*/}; \
203 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
204 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
205 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
206 fi; \
1261b4b3
AL
207 done
208
525ff0f9 209ifneq (,$(BUILD_DOCS))
6fce0a99
SL
210 # Brute force to remove privacy-breach-logo lintian warning.
211 # We could have updated the upstream sources but it would complexify
212 # the rebase
b556761e
AL
213 @set -e; \
214 find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \
1add0b94 215 while read file; do \
b556761e 216 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
92f6ea48 217 sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
87a30969 218 -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
1add0b94 219 done
b125a683
MO
220 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
221endif
222
cf9ecdde 223override_dh_install-arch:
6fce0a99 224 dh_install
525ff0f9
AL
225 dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
226
a0022868
XL
227override_dh_install-indep:
228 dh_install
525ff0f9
AL
229 chmod -x \
230 debian/rust-gdb/usr/share/rust-gdb/*.py \
231 debian/rust-lldb/usr/share/rust-lldb/*.py
35329365 232 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%)
f40dfcc0
XL
233 # Get rid of lintian warnings
234 find debian/rust-src/usr/src/rust \
235 \( -name .gitignore \
236 -o -name 'LICENSE*' \
237 -o -name 'LICENCE' \
238 -o -name 'license' \
239 -o -name 'COPYING*' \
240 \) -delete
241 cd debian/rust-src/usr/src/rust && chmod -x \
242 src/etc/gdb_rust_pretty_printing.py \
243 src/etc/adb_run_wrapper.sh \
244 src/compiler-rt/test/builtins/Unit/ppc/test
1c8ac2b0 245
bc0aa84e
AL
246override_dh_installchangelogs:
247 dh_installchangelogs RELEASES.md
248
249override_dh_installdocs:
250 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
251
eef1f4e3
AL
252override_dh_compress:
253 dh_compress -X.woff
254
525ff0f9
AL
255override_dh_makeshlibs:
256 dh_makeshlibs -V
257
258 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
259 # structure, so we have to do this ourselves.
260 install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
33766656 261 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
525ff0f9
AL
262 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
263 while read name version; do \
264 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
265 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
266 chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
267 chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
268
269override_dh_shlibdeps:
270 dh_shlibdeps -- -x$(LIBSTD_PKG)
427dce5b
XL
271
272QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
75be2bb3 273source_orig-stage0:
16dfb283
XL
274 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
275 $(MAKE) -f debian/rules clean
75be2bb3 276 debian/make_orig-stage0_tarball.sh
16dfb283
XL
277 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
278 rm -rf .pc