]> git.lizzy.rs Git - rust.git/blob - mk/dist.mk
Auto merge of #35871 - bluss:cstring-new, r=alexcrichton
[rust.git] / mk / dist.mk
1 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 ######################################################################
12 # Distribution
13 ######################################################################
14
15 # Primary targets:
16 #
17 # * dist - make all distribution artifacts
18 # * distcheck - sanity check dist artifacts
19 # * dist-tar-src - source tarballs
20 # * dist-tar-bins - Ad-hoc Unix binary installers
21 # * dist-docs - Stage docs for upload
22
23 PKG_NAME := $(CFG_PACKAGE_NAME)
24 STD_PKG_NAME := rust-std-$(CFG_PACKAGE_VERS)
25 DOC_PKG_NAME := rust-docs-$(CFG_PACKAGE_VERS)
26 MINGW_PKG_NAME := rust-mingw-$(CFG_PACKAGE_VERS)
27 SRC_PKG_NAME := rust-src-$(CFG_PACKAGE_VERS)
28
29 # License suitable for displaying in a popup
30 LICENSE.txt: $(S)COPYRIGHT $(S)LICENSE-APACHE $(S)LICENSE-MIT
31         cat $^ > $@
32
33
34 ######################################################################
35 # Source tarball
36 ######################################################################
37
38 PKG_TAR = dist/$(PKG_NAME)-src.tar.gz
39
40 PKG_GITMODULES := $(S)src/llvm $(S)src/compiler-rt \
41                   $(S)src/rt/hoedown $(S)src/jemalloc
42 PKG_FILES := \
43     $(S)COPYRIGHT                              \
44     $(S)LICENSE-APACHE                         \
45     $(S)LICENSE-MIT                            \
46     $(S)CONTRIBUTING.md                        \
47     $(S)README.md                              \
48     $(S)RELEASES.md                            \
49     $(S)configure $(S)Makefile.in              \
50     $(S)man                                    \
51     $(addprefix $(S)src/,                      \
52       bootstrap                                \
53       build_helper                             \
54       doc                                      \
55       driver                                   \
56       etc                                      \
57       $(foreach crate,$(CRATES),lib$(crate))   \
58       libcollectionstest                       \
59       libcoretest                              \
60       libbacktrace                             \
61       rt                                       \
62       rtstartup                                \
63       rustllvm                                 \
64       rustc                                    \
65       stage0.txt                               \
66       rust-installer                           \
67       tools                                    \
68       test)                                    \
69     $(PKG_GITMODULES)                          \
70     $(filter-out config.stamp, \
71                  $(MKFILES_FOR_TARBALL))
72
73 UNROOTED_PKG_FILES := $(patsubst $(S)%,./%,$(PKG_FILES))
74
75 tmp/dist/$$(SRC_PKG_NAME)-image: $(PKG_FILES)
76         @$(call E, making src image)
77         $(Q)rm -Rf tmp/dist/$(SRC_PKG_NAME)-image
78         $(Q)mkdir -p tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src/rust
79         $(Q)tar \
80          -C $(S) \
81          -f - \
82          --exclude-vcs \
83          --exclude=*~ \
84          --exclude=*.pyc \
85          --exclude=*/llvm/test/*/*.ll \
86          --exclude=*/llvm/test/*/*.td \
87          --exclude=*/llvm/test/*/*.s \
88          --exclude=*/llvm/test/*/*/*.ll \
89          --exclude=*/llvm/test/*/*/*.td \
90          --exclude=*/llvm/test/*/*/*.s \
91          -c $(UNROOTED_PKG_FILES) | tar -x -f - -C tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src/rust
92
93 $(PKG_TAR): tmp/dist/$$(SRC_PKG_NAME)-image
94         @$(call E, making $@)
95         $(Q)tar -czf $(PKG_TAR) -C tmp/dist/$(SRC_PKG_NAME)-image/lib/rustlib/src rust --transform 's,^rust,$(PKG_NAME),S'
96
97 dist-tar-src: $(PKG_TAR)
98
99 distcheck-tar-src: dist-tar-src
100         $(Q)rm -Rf tmp/distcheck/$(PKG_NAME)
101         $(Q)rm -Rf tmp/distcheck/srccheck
102         $(Q)mkdir -p tmp/distcheck
103         @$(call E, unpacking $(PKG_TAR) in tmp/distcheck/$(PKG_NAME))
104         $(Q)cd tmp/distcheck && tar -xzf ../../$(PKG_TAR)
105         @$(call E, configuring in tmp/distcheck/srccheck)
106         $(Q)mkdir -p tmp/distcheck/srccheck
107         $(Q)cd tmp/distcheck/srccheck && ../$(PKG_NAME)/configure
108         @$(call E, making 'check' in tmp/distcheck/srccheck)
109         $(Q)+make -C tmp/distcheck/srccheck check
110         @$(call E, making 'clean' in tmp/distcheck/srccheck)
111         $(Q)+make -C tmp/distcheck/srccheck clean
112         $(Q)rm -Rf tmp/distcheck/$(PKG_NAME)
113         $(Q)rm -Rf tmp/distcheck/srccheck
114
115
116 ######################################################################
117 # Unix binary installer tarballs
118 ######################################################################
119
120 define DEF_START_INSTALLER
121 dist-install-dir-$(1)-%: PREPARE_DIR_CMD=$(DEFAULT_PREPARE_DIR_CMD)
122 dist-install-dir-$(1)-%: PREPARE_BIN_CMD=$(DEFAULT_PREPARE_BIN_CMD)
123 dist-install-dir-$(1)-%: PREPARE_LIB_CMD=$(DEFAULT_PREPARE_LIB_CMD)
124 dist-install-dir-$(1)-%: PREPARE_MAN_CMD=$(DEFAULT_PREPARE_MAN_CMD)
125 dist-install-dir-$(1)-%: PREPARE_CLEAN=true
126
127 $$(eval $$(call DEF_PREPARE,dir-$(1)))
128 endef
129
130 $(foreach target,$(CFG_TARGET),\
131   $(eval $(call DEF_START_INSTALLER,$(target))))
132
133 define DEF_INSTALLER
134
135 dist-install-dir-$(1)-host: PREPARE_HOST=$(1)
136 dist-install-dir-$(1)-host: PREPARE_TARGETS=$(2)
137 dist-install-dir-$(1)-host: PREPARE_DEST_DIR=tmp/dist/$$(PKG_NAME)-$(1)-image
138 dist-install-dir-$(1)-host: prepare-base-dir-$(1)-host docs
139         $$(Q)mkdir -p $$(PREPARE_DEST_DIR)/share/doc/rust
140         $$(Q)$$(PREPARE_MAN_CMD) $$(S)COPYRIGHT $$(PREPARE_DEST_DIR)/share/doc/rust
141         $$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-APACHE $$(PREPARE_DEST_DIR)/share/doc/rust
142         $$(Q)$$(PREPARE_MAN_CMD) $$(S)LICENSE-MIT $$(PREPARE_DEST_DIR)/share/doc/rust
143         $$(Q)$$(PREPARE_MAN_CMD) $$(S)README.md $$(PREPARE_DEST_DIR)/share/doc/rust
144
145 prepare-overlay-$(1):
146         $$(Q)rm -Rf tmp/dist/$$(PKG_NAME)-$(1)-overlay
147         $$(Q)mkdir -p tmp/dist/$$(PKG_NAME)-$(1)-overlay
148         $$(Q)cp $$(S)COPYRIGHT tmp/dist/$$(PKG_NAME)-$(1)-overlay/
149         $$(Q)cp $$(S)LICENSE-APACHE tmp/dist/$$(PKG_NAME)-$(1)-overlay/
150         $$(Q)cp $$(S)LICENSE-MIT tmp/dist/$$(PKG_NAME)-$(1)-overlay/
151         $$(Q)cp $$(S)README.md tmp/dist/$$(PKG_NAME)-$(1)-overlay/
152 # This tiny morsel of metadata is used by rust-packaging
153         $$(Q)echo "$(CFG_VERSION)" > tmp/dist/$$(PKG_NAME)-$(1)-overlay/version
154
155 dist/$$(PKG_NAME)-$(1).tar.gz: dist-install-dir-$(1)-host prepare-overlay-$(1)
156         @$(call E, build: $$@)
157 # On a MinGW target we've got a few runtime DLL dependencies that we need
158 # to include. THe first argument to `make-win-dist` is where to put these DLLs
159 # (the image we're creating) and the second argument is a junk directory to
160 # ignore all the other MinGW stuff the script creates.
161 ifeq ($$(findstring pc-windows-gnu,$(1)),pc-windows-gnu)
162         $$(Q)rm -Rf tmp/dist/win-rust-gcc-$(1)
163         $$(Q)$$(CFG_PYTHON) $$(S)src/etc/make-win-dist.py \
164                 tmp/dist/$$(PKG_NAME)-$(1)-image \
165                 tmp/dist/win-rust-gcc-$(1) $(1)
166 endif
167 # On 32-bit MinGW we're always including a DLL which needs some extra licenses
168 # to distribute. On 64-bit MinGW we don't actually distribute anything requiring
169 # us to distribute a license but it's likely that the install will *also*
170 # include the rust-mingw package down below, which also need licenses, so to be
171 # safe we just inlude it here in all MinGW packages.
172 ifdef CFG_WINDOWSY_$(1)
173 ifeq ($$(findstring $(1),gnu),gnu)
174         $$(Q)cp -r $$(S)src/etc/third-party \
175                 tmp/dist/$$(PKG_NAME)-$(1)-image/share/doc/
176 endif
177 endif
178         $$(Q)$$(S)src/rust-installer/gen-installer.sh \
179                 --product-name=Rust \
180                 --rel-manifest-dir=rustlib \
181                 --success-message=Rust-is-ready-to-roll. \
182                 --image-dir=tmp/dist/$$(PKG_NAME)-$(1)-image \
183                 --work-dir=tmp/dist \
184                 --output-dir=dist \
185                 --non-installed-overlay=tmp/dist/$$(PKG_NAME)-$(1)-overlay \
186                 --package-name=$$(PKG_NAME)-$(1) \
187                 --component-name=rustc \
188                 --legacy-manifest-dirs=rustlib,cargo
189         $$(Q)rm -R tmp/dist/$$(PKG_NAME)-$(1)-image
190
191 dist-doc-install-dir-$(1): docs
192         $$(Q)mkdir -p tmp/dist/$$(DOC_PKG_NAME)-$(1)-image/share/doc/rust
193         $$(Q)cp -r doc tmp/dist/$$(DOC_PKG_NAME)-$(1)-image/share/doc/rust/html
194
195 dist/$$(DOC_PKG_NAME)-$(1).tar.gz: dist-doc-install-dir-$(1)
196         @$(call E, build: $$@)
197         $$(Q)$$(S)src/rust-installer/gen-installer.sh \
198                 --product-name=Rust-Documentation \
199                 --rel-manifest-dir=rustlib \
200                 --success-message=Rust-documentation-is-installed. \
201                 --image-dir=tmp/dist/$$(DOC_PKG_NAME)-$(1)-image \
202                 --work-dir=tmp/dist \
203                 --output-dir=dist \
204                 --package-name=$$(DOC_PKG_NAME)-$(1) \
205                 --component-name=rust-docs \
206                 --legacy-manifest-dirs=rustlib,cargo \
207                 --bulk-dirs=share/doc/rust/html
208         $$(Q)rm -R tmp/dist/$$(DOC_PKG_NAME)-$(1)-image
209
210 # Creates the rust-mingw package, and the first argument to make-win-dist is a
211 # "temporary directory" which is just thrown away (this contains the runtime
212 # DLLs included in the rustc package above) and the second argument is where to
213 # place all the MinGW components (which is what we want).
214 dist-mingw-install-dir-$(1):
215         $$(Q)mkdir -p tmp/dist/rust-mingw-tmp-$(1)-image
216         $$(Q)rm -Rf tmp/dist/$$(MINGW_PKG_NAME)-$(1)-image
217         $$(Q)$$(CFG_PYTHON) $$(S)src/etc/make-win-dist.py \
218                 tmp/dist/rust-mingw-tmp-$(1)-image \
219                 tmp/dist/$$(MINGW_PKG_NAME)-$(1)-image $(1)
220
221 dist/$$(MINGW_PKG_NAME)-$(1).tar.gz: dist-mingw-install-dir-$(1)
222         @$(call E, build: $$@)
223         $$(Q)$$(S)src/rust-installer/gen-installer.sh \
224                 --product-name=Rust-MinGW \
225                 --rel-manifest-dir=rustlib \
226                 --success-message=Rust-MinGW-is-installed. \
227                 --image-dir=tmp/dist/$$(MINGW_PKG_NAME)-$(1)-image \
228                 --work-dir=tmp/dist \
229                 --output-dir=dist \
230                 --package-name=$$(MINGW_PKG_NAME)-$(1) \
231                 --component-name=rust-mingw \
232                 --legacy-manifest-dirs=rustlib,cargo
233         $$(Q)rm -R tmp/dist/$$(MINGW_PKG_NAME)-$(1)-image
234
235 endef
236
237 # $(1) - host
238 # $(2) - target
239 define DEF_INSTALLER_TARGETS
240
241 dist-install-dir-$(2)-target: PREPARE_HOST=$(1)
242 dist-install-dir-$(2)-target: PREPARE_TARGETS=$(2)
243 dist-install-dir-$(2)-target: PREPARE_DEST_DIR=tmp/dist/$$(STD_PKG_NAME)-$(2)-image
244 dist-install-dir-$(2)-target: prepare-base-dir-$(2)-target
245
246 dist/$$(STD_PKG_NAME)-$(2).tar.gz: dist-install-dir-$(2)-target
247         @$$(call E, build: $$@)
248         $$(Q)$$(S)src/rust-installer/gen-installer.sh \
249                 --product-name=Rust \
250                 --rel-manifest-dir=rustlib \
251                 --success-message=std-is-standing-at-the-ready. \
252                 --image-dir=tmp/dist/$$(STD_PKG_NAME)-$(2)-image \
253                 --work-dir=tmp/dist \
254                 --output-dir=dist \
255                 --package-name=$$(STD_PKG_NAME)-$(2) \
256                 --component-name=rust-std-$(2) \
257                 --legacy-manifest-dirs=rustlib,cargo
258         $$(Q)rm -R tmp/dist/$$(STD_PKG_NAME)-$(2)-image
259 endef
260
261 $(foreach host,$(CFG_HOST),\
262   $(eval $(call DEF_INSTALLER,$(host))))
263
264 dist/$(SRC_PKG_NAME).tar.gz: tmp/dist/$(SRC_PKG_NAME)-image
265         @$(call E, build: $@)
266         $(Q)$(S)src/rust-installer/gen-installer.sh \
267                 --product-name=Rust \
268                 --rel-manifest-dir=rustlib \
269                 --success-message=Awesome-Source. \
270                 --image-dir=tmp/dist/$(SRC_PKG_NAME)-image \
271                 --work-dir=tmp/dist \
272                 --output-dir=dist \
273                 --package-name=$(SRC_PKG_NAME) \
274                 --component-name=rust-src \
275                 --legacy-manifest-dirs=rustlib,cargo
276
277 # When generating packages for the standard library, we've actually got a lot of
278 # artifacts to choose from. Each of the CFG_HOST compilers will have a copy of
279 # the standard library for each CFG_TARGET, but we only want to generate one
280 # standard library package. As a result, for each entry in CFG_TARGET we need to
281 # pick a CFG_HOST to get the standard library from.
282 #
283 # In theory it doesn't actually matter what host we choose as it should be the
284 # case that all hosts produce the same set of libraries for a target (regardless
285 # of the host itself). Currently there is a bug in the compiler, however, which
286 # means this is not the case (see #29228 and #29235). To solve the first of
287 # those bugs, we prefer to select a standard library from the host it was
288 # generated from, allowing plugins to work in more situations.
289 #
290 # For all CFG_TARGET entries in CFG_HOST, however, we just pick CFG_BUILD as the
291 # host we slurp up a standard library from.
292 $(foreach host,$(CFG_HOST),\
293   $(eval $(call DEF_INSTALLER_TARGETS,$(host),$(host))))
294 $(foreach target,$(filter-out $(CFG_HOST),$(CFG_TARGET)),\
295   $(eval $(call DEF_INSTALLER_TARGETS,$(CFG_BUILD),$(target))))
296
297 ifdef CFG_WINDOWSY_$(CFG_BUILD)
298 define BUILD_MINGW_TARBALL
299 ifeq ($$(findstring gnu,$(1)),gnu)
300 MAYBE_MINGW_TARBALLS += dist/$(MINGW_PKG_NAME)-$(1).tar.gz
301 endif
302 endef
303
304 $(foreach host,$(CFG_HOST),\
305   $(eval $(call BUILD_MINGW_TARBALL,$(host))))
306 endif
307
308 ifeq ($(CFG_DISABLE_DOCS),)
309 MAYBE_DOC_TARBALLS=$(foreach host,$(CFG_HOST),dist/$(DOC_PKG_NAME)-$(host).tar.gz)
310 endif
311
312 dist-tar-bins: \
313         $(foreach host,$(CFG_HOST),dist/$(PKG_NAME)-$(host).tar.gz) \
314         $(foreach target,$(CFG_TARGET),dist/$(STD_PKG_NAME)-$(target).tar.gz) \
315         $(MAYBE_DOC_TARBALLS) $(MAYBE_MINGW_TARBALLS)
316
317 # Just try to run the compiler for the build host
318 distcheck-tar-bins: dist-tar-bins
319         @$(call E, checking binary tarball)
320         $(Q)rm -Rf tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)
321         $(Q)rm -Rf tmp/distcheck/tarbininstall
322         $(Q)mkdir -p tmp/distcheck
323         $(Q)cd tmp/distcheck && tar -xzf ../../dist/$(PKG_NAME)-$(CFG_BUILD).tar.gz
324         $(Q)mkdir -p tmp/distcheck/tarbininstall
325         $(Q)sh tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix=tmp/distcheck/tarbininstall
326         $(Q)sh tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)/install.sh --prefix=tmp/distcheck/tarbininstall --uninstall
327         $(Q)rm -Rf tmp/distcheck/$(PKG_NAME)-$(CFG_BUILD)
328         $(Q)rm -Rf tmp/distcheck/tarbininstall
329
330 ######################################################################
331 # Docs
332 ######################################################################
333
334 # Just copy the docs to a folder under dist with the appropriate name
335 # for uploading to S3
336 dist-docs: docs
337         $(Q) rm -Rf dist/doc
338         $(Q) mkdir -p dist/doc/
339         $(Q) cp -r doc dist/doc/$(CFG_PACKAGE_VERS)
340
341 distcheck-docs: dist-docs
342
343 ######################################################################
344 # Primary targets (dist, distcheck)
345 ######################################################################
346
347 MAYBE_DIST_TAR_SRC=dist-tar-src dist/$(SRC_PKG_NAME).tar.gz
348 MAYBE_DISTCHECK_TAR_SRC=distcheck-tar-src dist/$(SRC_PKG_NAME).tar.gz
349
350 # FIXME #13224: On OS X don't produce tarballs simply because --exclude-vcs don't work.
351 # This is a huge hack because I just don't have time to figure out another solution.
352 ifeq ($(CFG_OSTYPE), apple-darwin)
353 MAYBE_DIST_TAR_SRC=
354 MAYBE_DISTCHECK_TAR_SRC=
355 endif
356
357 # Don't bother with source tarballs on windows just because we historically haven't.
358 ifeq ($(CFG_OSTYPE), pc-windows-gnu)
359 MAYBE_DIST_TAR_SRC=
360 MAYBE_DISTCHECK_TAR_SRC=
361 endif
362
363 ifneq ($(CFG_DISABLE_DOCS),)
364 MAYBE_DIST_DOCS=
365 MAYBE_DISTCHECK_DOCS=
366 else
367 MAYBE_DIST_DOCS=dist-docs
368 MAYBE_DISTCHECK_DOCS=distcheck-docs
369 endif
370
371 dist: $(MAYBE_DIST_TAR_SRC) dist-tar-bins $(MAYBE_DIST_DOCS)
372
373 distcheck: $(MAYBE_DISTCHECK_TAR_SRC) distcheck-tar-bins $(MAYBE_DISTCHECK_DOCS)
374         $(Q)rm -Rf tmp/distcheck
375         @echo
376         @echo -----------------------------------------------
377         @echo "Rust ready for distribution (see ./dist)"
378         @echo -----------------------------------------------
379
380 .PHONY: dist distcheck