]>
Commit | Line | Data |
---|---|---|
be771b38 LB |
1 | #!/usr/bin/make -f |
2 | # -*- makefile -*- | |
3 | ||
b59979d9 | 4 | include /usr/share/dpkg/pkg-info.mk |
6472c211 | 5 | include /usr/share/dpkg/vendor.mk |
d75d48d6 | 6 | include /usr/share/dpkg/architecture.mk |
7d40d3e1 | 7 | include /usr/share/dpkg/buildflags.mk |
4888e768 | 8 | # TODO: more correct to use `[build] rustflags = []` list syntax in Cargo.toml |
a1140187 | 9 | RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS)) |
7d40d3e1 | 10 | export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS |
b59979d9 | 11 | |
525ff0f9 AL |
12 | # Defines DEB_*_RUST_TYPE triples |
13 | include debian/architecture.mk | |
693daed7 | 14 | export 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. | |
21 | CFLAGS += -Wno-misleading-indentation | |
22 | ||
d4357a26 | 23 | # Release type (one of beta, stable or nightly) |
0f9154de | 24 | RELEASE_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 | 30 | DEB_DESTDIR := $(CURDIR)/debian/tmp |
525ff0f9 | 31 | |
25f1c2fe XL |
32 | SED_VERSION_SHORT := sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/' |
33 | RUST_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | $(SED_VERSION_SHORT)) | |
4888e768 | 34 | RUST_LONG_VERSION := $(shell echo '$(DEB_VERSION_UPSTREAM)' | sed -re 's/([^+]+).*/\1/') |
888747f5 | 35 | LIBSTD_PKG := libstd-rust-$(RUST_VERSION) |
25f1c2fe | 36 | # Sed expression that matches the "rustc" we have in our Build-Depends field |
66deafc1 | 37 | SED_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. | |
3613a4e9 XL |
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 | |
0ace110a | 43 | DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr --release-channel=$(RELEASE_CHANNEL) --disable-debuginfo-only-std |
be771b38 | 44 | |
525ff0f9 | 45 | # Use system LLVM (comment out to use vendored LLVM) |
666f0397 XL |
46 | LLVM_VERSION = 4.0 |
47 | OLD_LLVM_VERSION = 3.9 | |
48 | DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-$(LLVM_VERSION) | |
8e396fda | 49 | RUSTBUILD = RUST_BACKTRACE=1 ./x.py |
3613a4e9 | 50 | RUSTBUILD_FLAGS = --config debian/config.toml -v --on-fail env |
0d3674eb XL |
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 = | |
1c8ac2b0 | 56 | |
25f1c2fe XL |
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 | ||
427dce5b XL |
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 | # | |
427dce5b | 65 | PRECONFIGURE_CHECK = : |
75be2bb3 | 66 | HAVE_BINARY_TARBALL := $(shell ls -1 stage0/*/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l) |
571f0d20 MK |
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)) | |
16dfb283 XL |
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. | |
427dce5b XL |
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. | |
75be2bb3 | 84 | # In this case, the rust build scripts will download a stage0 into stage0/ and use that. |
b9a40c91 | 85 | # We don't need to do anything specific in this build file, so this case is empty. |
427dce5b | 86 | else |
16dfb283 XL |
87 | # Case B (Bootstrapping a new distro): the extracted source tree does |
88 | # include a bootstrapping tarball for the current architecture; see the | |
75be2bb3 | 89 | # `source_orig-stage0` target below on how to build this. |
427dce5b XL |
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 | |
16dfb283 | 93 | # that rustc isn't a Build-Depends for the current architecture. |
25f1c2fe XL |
94 | ifneq (,$(shell $(SED_RUSTC_BUILDDEP))) |
95 | ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)')) | |
75be2bb3 | 96 | PRECONFIGURE_CHECK = $(error found matches for stage0/*/*$(DEB_HOST_RUST_TYPE)*, \ |
16dfb283 XL |
97 | but rustc might be a Build-Depends for $(DEB_HOST_ARCH)) |
98 | endif | |
427dce5b | 99 | endif |
1c8ac2b0 SL |
100 | endif |
101 | ||
102 | BUILD_DOCS = 1 | |
120b4d47 | 103 | ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES))) |
525ff0f9 | 104 | DEB_CONFIGURE_FLAGS += --disable-docs |
2e97839d | 105 | BUILD_DOCS = |
1c8ac2b0 SL |
106 | endif |
107 | ||
108 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) | |
525ff0f9 | 109 | DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm |
1c8ac2b0 SL |
110 | endif |
111 | ||
35329365 XL |
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 \ | |
35329365 | 115 | src/etc/__pycache__/ |
1c8ac2b0 | 116 | |
170f9149 XL |
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 | ||
be771b38 | 122 | %: |
170f9149 | 123 | $(SYSTEM_WORKAROUNDS) dh $@ --parallel |
be771b38 | 124 | |
04c12273 XL |
125 | .PHONY: build |
126 | build: | |
170f9149 | 127 | $(SYSTEM_WORKAROUNDS) dh $@ --parallel |
04c12273 | 128 | |
de1de54b XL |
129 | override_dh_clean: |
130 | dh_clean -Xsrc/vendor/bitflags/Cargo.toml.orig | |
131 | ||
b1076f25 XL |
132 | debian/configure-upstream: debian/config.toml debian/rules |
133 | rm -f "$@" | |
134 | echo '#!/bin/sh' >> "$@" | |
6a9e99e9 | 135 | echo '# This script can be used to configure a mostly-clean upstream checkout' >> "$@" |
b1076f25 XL |
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 | ||
01dc6ef4 XL |
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)" \ | |
666f0397 | 150 | -DLLVM_VERSION="$(LLVM_VERSION)" \ |
01dc6ef4 XL |
151 | "$<" > "$@" |
152 | ||
153 | override_dh_auto_configure: debian/config.toml | |
5617e1bd | 154 | # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog |
666f0397 | 155 | ! grep --color=always -i 'll...\?$(subst .,\.,$(OLD_LLVM_VERSION))' --exclude=changelog -R debian |
427dce5b | 156 | $(PRECONFIGURE_CHECK) |
75be2bb3 | 157 | if [ -d stage0 ]; then mkdir -p build && ln -sfT ../stage0 build/cache; fi |
3281855a XL |
158 | # work around #842634 |
159 | if test $$(grep "127.0.0.1\s*localhost" /etc/hosts | wc -l) -gt 1; then \ | |
ed6f7eed | 160 | debian/ensure-patch -N debian/patches/d-host-duplicates.patch; fi |
4888e768 | 161 | PATH="$$PWD/debian/bin:$$PATH" \ |
525ff0f9 | 162 | ./configure $(DEB_CONFIGURE_FLAGS) |
1c8ac2b0 | 163 | |
11c430be | 164 | override_dh_auto_clean: |
f40dfcc0 | 165 | $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile |
01dc6ef4 | 166 | $(RM) -rf $(SRC_CLEAN) debian/config.toml |
11c430be | 167 | |
ea192313 XL |
168 | # upstream bundles this in the source, but in Debian we rebuild everything yo |
169 | generate-sources: | |
170 | $(MAKE) -C src/rt/hoedown src/html_blocks.c | |
1c8ac2b0 | 171 | |
ea192313 | 172 | override_dh_auto_build-arch: generate-sources |
04c12273 | 173 | $(RUSTBUILD) build $(RUSTBUILD_FLAGS) |
ea192313 | 174 | |
e408bc2c XL |
175 | # note: this is only for buildds that want to do a separate arch:all build; |
176 | # there is no point running this yourself "to save time" since it implicitly | |
177 | # depends on build-arch anyways. | |
ea192313 | 178 | override_dh_auto_build-indep: generate-sources |
e408bc2c | 179 | ifneq (,$(BUILD_DOCS)) |
1fd63ebe XL |
180 | # Rust has a weird way of configuring whether to build docs or not |
181 | sed -i -e 's/^docs = false/docs = true/' debian/config.toml | |
04c12273 XL |
182 | $(RUSTBUILD) doc $(RUSTBUILD_FLAGS) |
183 | endif | |
184 | ||
7958f3db XL |
185 | RUN_TESTS = \ |
186 | if $(1); then \ | |
04c12273 | 187 | : ; \ |
6472c211 | 188 | elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \ |
04c12273 | 189 | false; \ |
6472c211 XL |
190 | elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \ |
191 | false ; \ | |
04c12273 XL |
192 | else \ |
193 | echo "====================================================="; \ | |
194 | echo "WARNING: Ignoring test failures in the rust testsuite"; \ | |
195 | echo "====================================================="; \ | |
196 | fi | |
7958f3db XL |
197 | |
198 | override_dh_auto_test-arch: | |
347f6206 XL |
199 | # ensure that rustc_llvm is actually dynamically linked to libLLVM |
200 | set -e; find build/*/stage2/lib/rustlib/* -name '*rustc_llvm*.so' | \ | |
201 | while read x; do \ | |
202 | stat -c '%s %n' "$$x"; \ | |
203 | objdump -p "$$x" | grep -q "NEEDED.*LLVM"; \ | |
204 | test "$$(stat -c %s "$$x")" -lt 6000000; \ | |
205 | done | |
7958f3db | 206 | ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS))) |
8e396fda | 207 | $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast $(RUSTBUILD_FLAGS) $(RUSTBUILD_TEST_FLAGS)) |
0d3674eb XL |
208 | # don't continue if RUSTBUILD_TEST_FLAGS is non-empty |
209 | test -z "$(RUSTBUILD_TEST_FLAGS)" | |
e408bc2c | 210 | endif |
becfe001 | 211 | |
04c12273 | 212 | override_dh_auto_test-indep: |
7958f3db XL |
213 | ifneq (,$(BUILD_DOCS)) |
214 | ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS))) | |
215 | # Run all rules that test the docs, i.e. in step.rs that depend on default:doc | |
8e396fda | 216 | $(call RUN_TESTS,$(RUSTBUILD) test --no-fail-fast src/tools/linkchecker $(RUSTBUILD_FLAGS)) |
7958f3db XL |
217 | endif |
218 | endif | |
04c12273 | 219 | |
23d2674b | 220 | override_dh_auto_install: |
6a9e99e9 | 221 | DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) install $(RUSTBUILD_FLAGS) |
525ff0f9 AL |
222 | |
223 | mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/ | |
224 | mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/ | |
6fce0a99 | 225 | |
1261b4b3 | 226 | # Replace duplicated compile-time/run-time dylibs with symlinks |
525ff0f9 AL |
227 | @set -e; \ |
228 | for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \ | |
229 | name=$${f##*/}; \ | |
230 | if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \ | |
231 | echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \ | |
232 | ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \ | |
233 | fi; \ | |
1261b4b3 AL |
234 | done |
235 | ||
525ff0f9 | 236 | ifneq (,$(BUILD_DOCS)) |
6fce0a99 SL |
237 | # Brute force to remove privacy-breach-logo lintian warning. |
238 | # We could have updated the upstream sources but it would complexify | |
239 | # the rebase | |
b556761e AL |
240 | @set -e; \ |
241 | find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \ | |
1add0b94 | 242 | while read file; do \ |
b556761e | 243 | topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \ |
92f6ea48 | 244 | sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \ |
87a30969 | 245 | -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \ |
1add0b94 | 246 | done |
b125a683 MO |
247 | find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete; |
248 | endif | |
249 | ||
cf9ecdde | 250 | override_dh_install-arch: |
6fce0a99 | 251 | dh_install |
525ff0f9 AL |
252 | dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/ |
253 | ||
a0022868 XL |
254 | override_dh_install-indep: |
255 | dh_install | |
525ff0f9 AL |
256 | chmod -x \ |
257 | debian/rust-gdb/usr/share/rust-gdb/*.py \ | |
258 | debian/rust-lldb/usr/share/rust-lldb/*.py | |
35329365 | 259 | $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%) |
f40dfcc0 XL |
260 | # Get rid of lintian warnings |
261 | find debian/rust-src/usr/src/rust \ | |
262 | \( -name .gitignore \ | |
263 | -o -name 'LICENSE*' \ | |
264 | -o -name 'LICENCE' \ | |
265 | -o -name 'license' \ | |
266 | -o -name 'COPYING*' \ | |
267 | \) -delete | |
268 | cd debian/rust-src/usr/src/rust && chmod -x \ | |
269 | src/etc/gdb_rust_pretty_printing.py \ | |
270 | src/etc/adb_run_wrapper.sh \ | |
271 | src/compiler-rt/test/builtins/Unit/ppc/test | |
1c8ac2b0 | 272 | |
bc0aa84e AL |
273 | override_dh_installchangelogs: |
274 | dh_installchangelogs RELEASES.md | |
275 | ||
276 | override_dh_installdocs: | |
277 | dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc | |
278 | ||
eef1f4e3 AL |
279 | override_dh_compress: |
280 | dh_compress -X.woff | |
281 | ||
525ff0f9 AL |
282 | override_dh_makeshlibs: |
283 | dh_makeshlibs -V | |
284 | ||
285 | # dh_makeshlibs doesn't support our "libfoo-version.so" naming | |
286 | # structure, so we have to do this ourselves. | |
287 | install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN | |
33766656 | 288 | LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \ |
525ff0f9 AL |
289 | sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \ |
290 | while read name version; do \ | |
291 | echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \ | |
292 | done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs | |
293 | chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs | |
294 | chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs | |
295 | ||
296 | override_dh_shlibdeps: | |
297 | dh_shlibdeps -- -x$(LIBSTD_PKG) | |
427dce5b XL |
298 | |
299 | QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi | |
75be2bb3 | 300 | source_orig-stage0: |
16dfb283 XL |
301 | QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE) |
302 | $(MAKE) -f debian/rules clean | |
75be2bb3 | 303 | debian/make_orig-stage0_tarball.sh |
16dfb283 XL |
304 | QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE) |
305 | rm -rf .pc |