]> git.proxmox.com Git - rustc.git/blob - debian/rules
Simpler way of doing the rust-src package
[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/architecture.mk
6 include /usr/share/dpkg/buildflags.mk
7 #RUSTFLAGS = -C link-args="$(LDFLAGS)"
8 # temporary workaround for https://github.com/rust-lang/rust/issues/31529
9 # this will FAIL if LDFLAGS itself contains shell-interpreted chars beyond
10 # unquoted spaces (that addprefix works around the failure of)
11 RUSTFLAGS = $(addprefix -C link-args=,$(LDFLAGS))
12 export CFLAGS CXXFLAGS CPPFLAGS LDFLAGS RUSTFLAGS
13
14 # see https://github.com/rust-lang/rust/issues/37320
15 # it should be possible to remove this in the next Debian release
16 export MALLOC_CONF = lg_dirty_mult:-1
17
18 # Defines DEB_*_RUST_TYPE triples
19 include debian/architecture.mk
20
21 # Uncomment this to turn on verbose mode.
22 #export DH_VERBOSE=1
23
24 # When using sudo pbuilder, this will cause mk/install.mk to run sudo,
25 # but we don't need sudo as a build-dep for the package if we unexport
26 # the SUDO_USER variable.
27 unexport SUDO_USER
28
29 # src/rt/miniz.c (incorrectly) triggers -Wmisleading-indentation with
30 # gcc-6. See bug #811573.
31 CFLAGS += -Wno-misleading-indentation
32
33 # Release type (one of beta, stable or nightly)
34 RELEASE_CHANNEL := stable
35 # See also ./build-preview-dsc.sh for a script that builds a beta/nightly .dsc
36 # out of this packaging. Furthermore, if the build breaks after importing a new
37 # upstream stable release, check the do_temporary_fixup function in that file
38 # to see if we already know what fix to make.
39
40 DEB_DESTDIR := $(CURDIR)/debian/tmp
41
42 RUST_VERSION := $(shell dpkg-parsechangelog --show-field Version | sed -re 's/([^.]+)\.([^.]+)\..*/\1.\2/')
43 RUST_LONG_VERSION := $(shell dpkg-parsechangelog --show-field Version | sed -re 's/([^+]+).*/\1/')
44 LIBSTD_PKG := libstd-rust-$(RUST_VERSION)
45
46 # These are the normal build flags
47 DEB_CONFIGURE_FLAGS = \
48 --build=$(DEB_BUILD_RUST_TYPE) \
49 --host=$(DEB_HOST_RUST_TYPE) \
50 --target=$(DEB_TARGET_RUST_TYPE) \
51 --disable-manage-submodules \
52 --release-channel=$(RELEASE_CHANNEL) \
53 --prefix=/usr \
54 --enable-vendor --disable-locked-deps \
55 --enable-llvm-link-shared
56
57 # Use system LLVM (comment out to use vendored LLVM)
58 OLD_LLVM_VERSION = 3.8
59 DEB_CONFIGURE_FLAGS += --llvm-root=/usr/lib/llvm-3.9
60 RUSTBUILD = ./x.py
61 RUSTBUILD_FLAGS = -v
62
63 # Below we detect how we're supposed to bootstrap the stage0 compiler. See
64 # README.Debian for more details of the cases described below.
65 #
66 # Sed expression that matches the "rustc" we have in our Build-Depends field
67 SED_RUSTC_BUILDDEP := /^Build-Depends:/,/^[^[:space:]\#]/{/\s*rustc.*,/$$action}
68 PRECONFIGURE_CHECK = :
69 HAVE_BINARY_TARBALL := $(shell ls -1 dl/*$(DEB_HOST_RUST_TYPE)* 2>/dev/null | wc -l)
70 # allow not using the binary tarball although it exists
71 #ifneq (,$(filter $(DEB_HOST_ARCH), amd64 arm64 armhf i386 powerpc ppc64el s390x))
72 # HAVE_BINARY_TARBALL := 0
73 #endif
74 ifeq (0,$(HAVE_BINARY_TARBALL))
75 # Case A (Building from source): the extracted source tree does not include
76 # a bootstrapping tarball for the current architecture e.g. because the
77 # distro already has a rustc for this arch, or the uploader expects that
78 # this requirement be fulfilled in some other way.
79 #
80 # Case A-1: the builder did not select the "pkg.rustc.dlstage0" build profile.
81 # In this case, we use the distro's rustc - either the previous or current version.
82 ifeq (,$(findstring pkg.rustc.dlstage0,$(DEB_BUILD_PROFILES)))
83 DEB_CONFIGURE_FLAGS += --enable-local-rust --local-rust-root=/usr
84 endif
85 #
86 # Case A-2: the builder selected the "dlstage0" build profile.
87 # In this case, the rust build scripts will download a stage0 into dl/ and use that.
88 # We don't need to do anything specific in this build file, so this case is empty.
89 else
90 # Case B (Bootstrapping a new distro): the extracted source tree does
91 # include a bootstrapping tarball for the current architecture; see the
92 # `source_orig-dl` target below on how to build this.
93 #
94 # In this case, we'll bootstrap from the stage0 given in that tarball.
95 # To ensure the uploader of the .dsc didn't make a mistake, we first check
96 # that rustc isn't a Build-Depends for the current architecture.
97 ifneq (,$(shell action=p; sed -ne "$(SED_RUSTC_BUILDDEP)" debian/control))
98 ifeq (,$(shell action=p; sed -ne "$(SED_RUSTC_BUILDDEP)" debian/control | grep '!$(DEB_HOST_ARCH)'))
99 PRECONFIGURE_CHECK = $(error found matches for dl/*$(DEB_HOST_RUST_TYPE)*, \
100 but rustc might be a Build-Depends for $(DEB_HOST_ARCH))
101 endif
102 endif
103 endif
104
105 BUILD_DOCS = 1
106 ifneq (,$(findstring nodoc,$(DEB_BUILD_PROFILES)))
107 DEB_CONFIGURE_FLAGS += --disable-docs
108 BUILD_DOCS =
109 endif
110
111 ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
112 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
113 endif
114
115 # Workaround for powerpc64le: no optimization
116 # TODO: can remove when https://github.com/rust-lang/rust/issues/39015 is fixed
117 ifneq (,$(findstring powerpc64le,$(DEB_TARGET_RUST_TYPE)))
118 DEB_CONFIGURE_FLAGS += --disable-optimize --disable-optimize-cxx --disable-optimize-llvm
119 endif
120
121 # Build products or non-source files in src/, that shouldn't go in rust-src
122 SRC_CLEAN = src/rt/hoedown/src/html_blocks.c \
123 src/bootstrap/bootstrap.pyc \
124 src/bootstrap/config.toml \
125 src/etc/__pycache__/
126
127 %:
128 dh $@ --parallel
129
130 .PHONY: build
131 build:
132 dh $@ --parallel
133
134 # Note: SHELL is not set by dash, but the configure script wants to use it
135 override_dh_auto_configure:
136 # fail the build if we have any instances of OLD_LLVM_VERSION in debian, except for debian/changelog
137 ! grep --color=always -i 'll...$(OLD_LLVM_VERSION)' --exclude=changelog -R debian
138 $(PRECONFIGURE_CHECK)
139 cp debian/config.toml src/bootstrap/config.toml
140 mkdir cargo # otherwise "install" fails, it's more strict than really needed
141 SHELL=/bin/sh PATH="$$PWD/debian/bin:$$PATH" DEB_HOST_ARCH="$(DEB_HOST_ARCH)" \
142 ./configure $(DEB_CONFIGURE_FLAGS)
143
144 override_dh_auto_clean:
145 $(RM) -rf ./build ./tmp ./.cargo config.stamp config.mk Makefile ./cargo
146 $(RM) -rf $(SRC_CLEAN)
147
148 # upstream bundles this in the source, but in Debian we rebuild everything yo
149 generate-sources:
150 $(MAKE) -C src/rt/hoedown src/html_blocks.c
151
152 override_dh_auto_build-arch: generate-sources
153 $(RUSTBUILD) build $(RUSTBUILD_FLAGS)
154
155 # note: this is only for buildds that want to do a separate arch:all build;
156 # there is no point running this yourself "to save time" since it implicitly
157 # depends on build-arch anyways.
158 override_dh_auto_build-indep: generate-sources
159 ifneq (,$(BUILD_DOCS))
160 $(RUSTBUILD) doc $(RUSTBUILD_FLAGS)
161 endif
162
163 override_dh_auto_test-arch:
164 ifeq (, $(filter nocheck,$(DEB_BUILD_OPTIONS)))
165 # Use non-parallel $(MAKE) here instead of dh_auto_test, otherwise the upstream
166 # Makefile will try to run N instances of the testrunner each of which will run
167 # N instances of rustc (there is also parallel logic in libtest.rs already).
168 if RUST_BACKTRACE=1 $(RUSTBUILD) test $(RUSTBUILD_FLAGS); then \
169 : ; \
170 elif [ $(DEB_DISTRIBUTION) != "experimental" ]; then \
171 false; \
172 else \
173 echo "====================================================="; \
174 echo "WARNING: Ignoring test failures in the rust testsuite"; \
175 echo "====================================================="; \
176 fi
177 endif
178
179 # No tests are applicable when only building arch:all packages.
180 # More specifically: when we do an arch-all build, some crates are not built.
181 # This makes some arch-dependent tests fail, so don't run them here.
182 override_dh_auto_test-indep:
183 true
184
185 override_dh_auto_install:
186 DESTDIR=$(DEB_DESTDIR) $(RUSTBUILD) dist $(RUSTBUILD_FLAGS) --install
187
188 mkdir -p $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
189 mv $(DEB_DESTDIR)/usr/lib/lib*.so $(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/
190
191 # Replace duplicated compile-time/run-time dylibs with symlinks
192 @set -e; \
193 for f in $(DEB_DESTDIR)/usr/lib/rustlib/$(DEB_HOST_RUST_TYPE)/lib/lib*.so; do \
194 name=$${f##*/}; \
195 if [ -f "$(DEB_DESTDIR)/usr/lib/$(DEB_HOST_MULTIARCH)/$$name" ]; then \
196 echo "ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f"; \
197 ln -sf ../../../$(DEB_HOST_MULTIARCH)/$$name $$f; \
198 fi; \
199 done
200
201 ifneq (,$(BUILD_DOCS))
202 # Brute force to remove privacy-breach-logo lintian warning.
203 # We could have updated the upstream sources but it would complexify
204 # the rebase
205 @set -e; \
206 find $(DEB_DESTDIR)/usr/share/doc/rust/html -iname '*.html' | \
207 while read file; do \
208 topdir=$$(echo "$$file" | sed 's,^$(DEB_DESTDIR)/usr/share/doc/rust/html/,,; s,/[^/]*$$,/,; s,^[^/]*$$,,; s,[^/]\+/,../,g'); \
209 sed -i -e "s,https://doc.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," \
210 -e "s,https://www.rust-lang.org/\(favicon.ico\|logos/rust-logo-32x32-blk.png\),$${topdir}rust-logo-32x32-blk.png," "$$file"; \
211 done
212 find $(DEB_DESTDIR) \( -iname '*.html' -empty -o -name .lock -o -name '*.inc' \) -delete;
213 endif
214
215 override_dh_install-arch:
216 dh_install
217 dh_install -p$(LIBSTD_PKG) usr/lib/$(DEB_HOST_MULTIARCH)/
218
219 override_dh_install-indep:
220 dh_install
221 chmod -x \
222 debian/rust-gdb/usr/share/rust-gdb/*.py \
223 debian/rust-lldb/usr/share/rust-lldb/*.py
224 $(RM) -rf $(SRC_CLEAN:%=debian/rust-src/usr/src/rust/%)
225
226 override_dh_installchangelogs:
227 dh_installchangelogs RELEASES.md
228
229 override_dh_installdocs:
230 dh_installdocs -X.tex -X.aux -X.log -X.out -X.toc
231
232 override_dh_compress:
233 dh_compress -X.woff
234
235 override_dh_makeshlibs:
236 dh_makeshlibs -V
237
238 # dh_makeshlibs doesn't support our "libfoo-version.so" naming
239 # structure, so we have to do this ourselves.
240 install -o 0 -g 0 -d debian/$(LIBSTD_PKG)/DEBIAN
241 LC_ALL=C ls debian/$(LIBSTD_PKG)/usr/lib/$(DEB_HOST_MULTIARCH)/lib*.so | \
242 sed -n 's,^.*/\(lib.*\)-\(.\+\)\.so$$,\1 \2,p' | \
243 while read name version; do \
244 echo "$$name $$version $(LIBSTD_PKG) (>= $(DEB_VERSION_UPSTREAM))"; \
245 done > debian/$(LIBSTD_PKG)/DEBIAN/shlibs
246 chmod 644 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
247 chown 0:0 debian/$(LIBSTD_PKG)/DEBIAN/shlibs
248
249 override_dh_shlibdeps:
250 dh_shlibdeps -- -x$(LIBSTD_PKG)
251
252 QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE = x=$$?; if [ $$x = 2 ]; then exit 0; else exit $$x; fi
253 source_orig-dl:
254 QUILT_PATCHES=debian/patches quilt push -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
255 $(MAKE) -f debian/rules clean
256 debian/make_orig-dl_tarball.sh
257 QUILT_PATCHES=debian/patches quilt pop -aq; $(QUILT_SPECIAL_SNOWFLAKE_RETURN_CODE)
258 rm -rf .pc