]> git.proxmox.com Git - rustc.git/blob - debian/rules
Work around https://github.com/rust-lang/rust/issues/42320
[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 .*,/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 DEB_CONFIGURE_FLAGS = --enable-llvm-link-shared --disable-dist-src --prefix=/usr
42
43 # Use system LLVM (comment out to use vendored LLVM)
44 OLD_LLVM_VERSION = 3.8
45 DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-3.9
46 RUSTBUILD = ./x.py
47 RUSTBUILD_FLAGS = --config debian/config.toml -v
48
49 update-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
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 #
57 PRECONFIGURE_CHECK = :
58 HAVE_BINARY_TARBALL := $(shell ls -1 dl/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
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
63 ifeq (0,$(HAVE_BINARY_TARBALL))
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.
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.
76 # In this case, the rust build scripts will download a stage0 into dl/ and use that.
77 # We don't need to do anything specific in this build file, so this case is empty.
78 else
79 # Case B (Bootstrapping a new distro): the extracted source tree does
80 # include a bootstrapping tarball for the current architecture; see the
81 # `source_orig-dl` target below on how to build this.
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
85 # that rustc isn't a Build-Depends for the current architecture.
86 ifneq (,$(shell $(SED_RUSTC_BUILDDEP)))
87 ifeq (,$(shell $(SED_RUSTC_BUILDDEP) | grep '!$(DEB_HOST_ARCH)'))
88 PRECONFIGURE_CHECK = $(error found matches for dl/*$(DEB_HOST_RUST_TYPE)*, \
89 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
90 endif
91 endif
92 endif
93
94 BUILD_DOCS = 1
95 ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
96 DEB_CONFIGURE_FLAGS += --disable-docs
97 BUILD_DOCS =
98 endif
99
100 ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
101 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
102 endif
103
104 # Workaround for powerpc64le: no optimization
105 # TODO: can remove when https://github.com/rust-lang/rust/issues/39015 is fixed
106 ifneq (,$(findstring powerpc64le,$(DEB_TARGET_RUST_TYPE)))
107 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
108 endif
109
110 # Build products or non-source files in src/, that shouldn't go in rust-src
111 SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
112 src/bootstrap/bootstrap.pyc \
113 src/etc/__pycache__/
114
115 %:
116 dh $@ --parallel
117
118 .PHONY: build
119 build:
120 dh $@ --parallel
121
122 debian/config.toml: debian/config.toml.in
123 m4 -DDEB_BUILD_RUST_TYPE="$(DEB_BUILD_RUST_TYPE)" \
124 -DDEB_HOST_RUST_TYPE="$(DEB_HOST_RUST_TYPE)" \
125 -DDEB_TARGET_RUST_TYPE="$(DEB_TARGET_RUST_TYPE)" \
126 -DRELEASE_CHANNEL="$(RELEASE_CHANNEL)" \
127 "$<" > "$@"
128
129 override_dh_auto_configure: debian/config.toml
130 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
131 ! grep --color=always -i 'll...?$(OLD_LLVM_VERSION)' --exclude=changelog -R debian
132 $(PRECONFIGURE_CHECK)
133 PATH="$$PWD/debian/bin:$$PATH" \
134 ./configure $(DEB_CONFIGURE_FLAGS)
135
136 override_dh_auto_clean:
137 $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile
138 $(RM) -rf $(SRC_CLEAN) debian/config.toml
139
140 # upstream bundles this in the source, but in Debian we rebuild everything yo
141 generate-sources:
142 $(MAKE) -C src/rt/hoedown src/html_blocks.c
143
144 override_dh_auto_build-arch: generate-sources
145 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
146
147 # note: this is only for buildds that want to do a separate arch:all build;
148 # there is no point running this yourself "to save time" since it implicitly
149 # depends on build-arch anyways.
150 override_dh_auto_build-indep: generate-sources
151 ifneq (,$(BUILD_DOCS))
152 # Rust has a weird way of configuring whether to build docs or not
153 sed -i -e 's/^docs = false/docs = true/' debian/config.toml
154 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
155 endif
156
157 override_dh_auto_test-arch:
158 ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
159 # Use non-parallel $(MAKE) here instead of dh_auto_test, otherwise the upstream
160 # Makefile will try to run N instances of the testrunner each of which will run
161 # N instances of rustc (there is also parallel logic in libtest.rs already).
162 if RUST_BACKTRACE=1 $(RUSTBUILD) test $(RUSTBUILD_FLAGS); then \
163 : ; \
164 elif [ $(DEB_VENDOR) = "Debian" -a $(DEB_DISTRIBUTION) != "experimental" ]; then \
165 false; \
166 elif [ $(DEB_VENDOR) = "Ubuntu" -a $(DEB_HOST_ARCH) != "s390x" ]; then \
167 false ; \
168 else \
169 echo "====================================================="; \
170 echo "WARNING: Ignoring test failures in the rust testsuite"; \
171 echo "====================================================="; \
172 fi
173 endif
174
175 # No tests are applicable when only building arch:all packages.
176 # More specifically: when we do an arch-all build, some crates are not built.
177 # This makes some arch-dependent tests fail, so don't run them here.
178 override_dh_auto_test-indep:
179 true
180
181 override_dh_auto_install:
182 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) dist $(RUSTBUILD_FLAGS) --install
183
184 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
185 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
186
187 # Replace duplicated compile-time/run-time dylibs with symlinks
188 @set -e; \
189 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
190 name=$${f##*/}; \
191 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
192 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
193 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
194 fi; \
195 done
196
197 ifneq (,$(BUILD_DOCS))
198 # Brute force to remove privacy-breach-logo lintian warning.
199 # We could have updated the upstream sources but it would complexify
200 # the rebase
201 @set -e; \
202 find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \
203 while read file; do \
204 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
205 sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
206 -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
207 done
208 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
209 endif
210
211 override_dh_install-arch:
212 dh_install
213 dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
214
215 override_dh_install-indep:
216 dh_install
217 chmod -x \
218 debian/rust-gdb/usr/share/rust-gdb/*.py \
219 debian/rust-lldb/usr/share/rust-lldb/*.py
220 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%)
221 # Get rid of lintian warnings
222 find debian/rust-src/usr/src/rust \
223 \( -name .gitignore \
224 -o -name 'LICENSE*' \
225 -o -name 'LICENCE' \
226 -o -name 'license' \
227 -o -name 'COPYING*' \
228 \) -delete
229 cd debian/rust-src/usr/src/rust && chmod -x \
230 src/etc/gdb_rust_pretty_printing.py \
231 src/etc/adb_run_wrapper.sh \
232 src/compiler-rt/test/builtins/Unit/ppc/test
233
234 override_dh_installchangelogs:
235 dh_installchangelogs RELEASES.md
236
237 override_dh_installdocs:
238 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
239
240 override_dh_compress:
241 dh_compress -X.woff
242
243 override_dh_makeshlibs:
244 dh_makeshlibs -V
245
246 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
247 # structure, so we have to do this ourselves.
248 install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
249 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
250 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
251 while read name version; do \
252 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
253 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
254 chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
255 chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
256
257 override_dh_shlibdeps:
258 dh_shlibdeps -- -x$(LIBSTD_PKG)
259
260 QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
261 source_orig-dl:
262 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
263 $(MAKE) -f debian/rules clean
264 debian/make_orig-dl_tarball.sh
265 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
266 rm -rf .pc