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