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