]> git.proxmox.com Git - rustc.git/blob - debian/rules
Merge branch 'debian/sid' into debian/experimental
[rustc.git] / debian / rules
1 #!/usr/bin/make -f
2 # -*- makefile -*-
3
4 include /usr/share/dpkg/pkg-info.mk
5 include /usr/share/dpkg/vendor.mk
6 include /usr/share/dpkg/architecture.mk
7 include /usr/share/dpkg/buildflags.mk
8 # TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml
9 RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
10 export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
11
12 # Defines DEB_*_RUST_TYPE triples
13 include debian/architecture.mk
14 export DEB_HOST_RUST_TYPE
15
16 # Uncomment this to turn on verbose mode.
17 #export DH_VERBOSE=1
18
19 # src/rt/miniz.c (incorrectly) triggers -Wmisleading-indentation with
20 # gcc-6. See bug #811573.
21 CFLAGS += -Wno-misleading-indentation
22
23 # Release type (one of beta, stable or nightly)
24 RELEASE_CHANNEL := stable
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.
29
30 DEB_DESTDIR := $(CURDIR)/debian/tmp
31
32 SED_VERSION_SHORT := sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/'
33 RUST_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | $(SED_VERSION_SHORT))
34 RUST_LONG_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -re 's/([^+]+).*/\1/')
35 LIBSTD_PKG := libstd-rust-$(RUST_VERSION)
36 # Sed expression that matches the "rustc" we have in our Build-Depends field
37 SED_RUSTC_BUILDDEP := sed -ne "/^Build-Depends:/,/^[^[:space:]\#]/{/^ *rustc:native .*,/p}" debian/control
38
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.
41 # Certain flags also need to be kept here *as well as* debian/config.toml.in
42 # because of https://github.com/rust-lang/rust/issues/43295
43 DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr --release-channel=$(RELEASE_CHANNEL) --disable-debuginfo-only-std
44
45 # Use system LLVM (comment out to use vendored LLVM)
46 LLVM_VERSION = 4.0
47 OLD_LLVM_VERSION = 3.9
48 DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-$(LLVM_VERSION)
49 RUSTBUILD = RUST_BACKTRACE=1 ./x.py
50 RUSTBUILD_FLAGS = --config debian/config.toml -v --on-fail env
51 # To run a specific test, run something like:
52 # $ debian/rules override_dh_auto_test-arch \
53 # RUSTBUILD_TEST_FLAGS="src/test/run-make --test-args extern-fn-struct"
54 # See src/bootstrap/README.md for more options.
55 RUSTBUILD_TEST_FLAGS =
56
57 update-version:
58 oldver=$(shell $(SED_RUSTC_BUILDDEP) | sed -ne 's/.*(<= \(.*\)).*/\1/gp' | $(SED_VERSION_SHORT)); \
59 newver=$(RUST_VERSION); \
60 if [ $$oldver != $$newver ]; then debian/update-version.sh $$oldver $$newver; fi
61
62 # Below we detect how we're supposed to bootstrap the stage0 compiler. See
63 # README.Debian for more details of the cases described below.
64 #
65 PRECONFIGURE_CHECK = :
66 HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
67 # allow not using the binary tarball although it exists
68 #ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
69 # HAVE_BINARY_TARBALL := 0
70 #endif
71 ifeq (0,$(HAVE_BINARY_TARBALL))
72 # Case A (Building from source): the extracted source tree does not include
73 # a bootstrapping tarball for the current architecture e.g. because the
74 # distro already has a rustc for this arch, or the uploader expects that
75 # this requirement be fulfilled in some other way.
76 #
77 # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
78 # In this case, we use the distro's rustc - either the previous or current version.
79 ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
80 DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
81 endif
82 #
83 # Case A-2: the builder selected the "dlstage0" build profile.
84 # In this case, the rust build scripts will download a stage0 into stage0/ and use that.
85 # We don't need to do anything specific in this build file, so this case is empty.
86 else
87 # Case B (Bootstrapping a new distro): the extracted source tree does
88 # include a bootstrapping tarball for the current architecture; see the
89 # `source_orig-stage0` target below on how to build this.
90 #
91 # In this case, we'll bootstrap from the stage0 given in that tarball.
92 # To ensure the uploader of the .dsc didn't make a mistake, we first check
93 # that rustc isn't a Build-Depends for the current architecture.
94 ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
95 ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
96 PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \
97 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
98 endif
99 endif
100 endif
101
102 BUILD_DOCS = 1
103 ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
104 DEB_CONFIGURE_FLAGS += --disable-docs
105 BUILD_DOCS =
106 endif
107
108 ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
109 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
110 endif
111
112 # Build products or non-source files in src/, that shouldn't go in rust-src
113 SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
114 src/bootstrap/bootstrap.pyc \
115 src/etc/__pycache__/
116
117 # Workaround for linux #865549
118 ifeq (0,$(shell test $$(uname -s) = "Linux" -a $$(getconf PAGESIZE) -gt 4096; echo $$?))
119 SYSTEM_WORKAROUNDS += ulimit -s $$(expr $$(getconf PAGESIZE) / 1024 '*' 256 + 8192);
120 endif
121
122 %:
123 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
124
125 .PHONY: build
126 build:
127 $(SYSTEM_WORKAROUNDS) dh $@ --parallel
128
129 override_dh_clean:
130 dh_clean -Xsrc/vendor/bitflags/Cargo.toml.orig
131
132 debian/configure-upstream: debian/config.toml debian/rules
133 rm -f "$@"
134 echo '#!/bin/sh' >> "$@"
135 echo '# This script can be used to configure a mostly-clean upstream checkout' >> "$@"
136 echo '# in case you need to test any differences between it and Debian' >> "$@"
137 echo 'set -e' >> "$@"
138 echo 'test -f ./configure' >> "$@"
139 echo 'cat > config.toml <<EOF' >> "$@"
140 cat debian/config.toml >> "$@"
141 echo 'EOF' >> "$@"
142 echo "./configure $(DEB_CONFIGURE_FLAGS)" >> "$@"
143 chmod +x "$@"
144
145 debian/config.toml: debian/config.toml.in
146 m4 -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
147 -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
148 -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
149 -DRELEASE_CHANNEL="$(RELEASE_CHANNEL)" \
150 -DLLVM_VERSION="$(LLVM_VERSION)" \
151 "$<" > "$@"
152
153 override_dh_auto_configure: debian/config.toml
154 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
155 ! grep --color=always -i 'll...\?$(subst .,\.,$(OLD_LLVM_VERSION))' --exclude=changelog -R debian
156 $(PRECONFIGURE_CHECK)
157 if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi
158 # work around #842634
159 if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \
160 debian/ensure-patch -N debian/patches/d-host-duplicates.patch; fi
161 # We patched mdbook so have to rm the checksums
162 debian/empty-cargo-checksum.py src/vendor/mdbook/.cargo-checksum.json
163 # Unfortunately upstream uses a duplicate copy of libbacktrace and wants to
164 # compile it again for rust-installer, see #43449
165 ln -rsf src/libbacktrace -t src/vendor/backtrace-sys/src/
166 debian/empty-cargo-checksum.py src/vendor/backtrace-sys/.cargo-checksum.json
167 # Link against system liblzma, see https://github.com/alexcrichton/xz2-rs/issues/16
168 echo 'fn main() { println!("cargo:rustc-link-lib=lzma"); }' > src/vendor/lzma-sys/build.rs
169 debian/empty-cargo-checksum.py src/vendor/lzma-sys/.cargo-checksum.json
170 # Do the actual configure
171 PATH="$$PWD/debian/bin:$$PATH" \
172 ./configure $(DEB_CONFIGURE_FLAGS)
173
174 override_dh_auto_clean:
175 $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile
176 $(RM) -rf $(SRC_CLEAN) debian/config.toml
177
178 # upstream bundles this in the source, but in Debian we rebuild everything yo
179 generate-sources:
180 $(MAKE) -C src/rt/hoedown src/html_blocks.c
181
182 override_dh_auto_build-arch: generate-sources
183 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
184
185 # note: this is only for buildds that want to do a separate arch:all build;
186 # there is no point running this yourself "to save time" since it implicitly
187 # depends on build-arch anyways.
188 override_dh_auto_build-indep: generate-sources
189 ifneq (,$(BUILD_DOCS))
190 # Rust has a weird way of configuring whether to build docs or not
191 sed -i -e 's/^docs = false/docs = true/' debian/config.toml
192 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
193 endif
194
195 RUN_TESTS = \
196 if $(1); then \
197 : ; \
198 elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
199 false; \
200 elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \
201 false ; \
202 else \
203 echo "====================================================="; \
204 echo "WARNING: Ignoring test failures in the rust testsuite"; \
205 echo "====================================================="; \
206 fi
207
208 override_dh_auto_test-arch:
209 # ensure that rustc_llvm is actually dynamically linked to libLLVM
210 set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \
211 while read x; do \
212 stat -c '%s %n' "$$x"; \
213 objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \
214 test "$$(stat -c %s "$$x")" -lt 6000000; \
215 done
216 ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
217 $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS))
218 # don't continue if RUSTBUILD_TEST_FLAGS is non-empty
219 test -z "$(RUSTBUILD_TEST_FLAGS)"
220 endif
221
222 override_dh_auto_test-indep:
223 ifneq (,$(BUILD_DOCS))
224 ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
225 # Run all rules that test the docs, i.e. in step.rs that depend on default:doc
226 $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast src/tools/linkchecker $(RUSTBUILD_FLAGS))
227 endif
228 endif
229
230 override_dh_auto_install:
231 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS)
232
233 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
234 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
235
236 # Replace duplicated compile-time/run-time dylibs with symlinks
237 @set -e; \
238 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
239 name=$${f##*/}; \
240 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
241 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
242 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
243 fi; \
244 done
245
246 ifneq (,$(BUILD_DOCS))
247 # Brute force to remove privacy-breach-logo lintian warning.
248 # We could have updated the upstream sources but it would complexify
249 # the rebase
250 @set -e; \
251 find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \
252 while read file; do \
253 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
254 sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
255 -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
256 done
257 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
258 endif
259
260 override_dh_install-arch:
261 dh_install
262 dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
263
264 override_dh_install-indep:
265 dh_install
266 chmod -x \
267 debian/rust-gdb/usr/share/rust-gdb/*.py \
268 debian/rust-lldb/usr/share/rust-lldb/*.py
269 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%)
270 # Get rid of lintian warnings
271 find debian/rust-src/usr/src/rust \
272 \( -name .gitignore \
273 -o -name 'LICENSE*' \
274 -o -name 'LICENCE' \
275 -o -name 'license' \
276 -o -name 'COPYING*' \
277 \) -delete
278 cd debian/rust-src/usr/src/rust && chmod -x \
279 src/etc/gdb_rust_pretty_printing.py \
280 src/compiler-rt/test/builtins/Unit/ppc/test
281
282 override_dh_installchangelogs:
283 dh_installchangelogs RELEASES.md
284
285 override_dh_installdocs:
286 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
287
288 override_dh_compress:
289 dh_compress -X.woff
290
291 override_dh_makeshlibs:
292 dh_makeshlibs -V
293
294 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
295 # structure, so we have to do this ourselves.
296 install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
297 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
298 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
299 while read name version; do \
300 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
301 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
302 chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
303 chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
304
305 override_dh_shlibdeps:
306 dh_shlibdeps -- -x$(LIBSTD_PKG)
307
308 QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
309 source_orig-stage0:
310 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
311 $(MAKE) -f debian/rules clean
312 debian/make_orig-stage0_tarball.sh
313 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
314 rm -rf .pc