-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrustup.mk
341 lines (307 loc) · 10.4 KB
/
rustup.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
ifndef _MK_RUSTUP_MK_
_MK_RUSTUP_MK_ := 1
#$(info ---> .make/rustup.mk)
ifndef GIT_ROOT
GIT_ROOT := $(shell git rev-parse --show-toplevel 2>/dev/null)
endif
ifndef MK_DIR
MK_DIR := $(GIT_ROOT)/.make
endif
include $(MK_DIR)/os.mk
include $(MK_DIR)/rust-target.mk
include $(MK_DIR)/curl.mk
# See https://substrate.stackexchange.com/a/9069/4489
# Don't forget to also update /rust-toolchain.toml !!
#RUSTUP_TOOLCHAIN := nightly-2023-08-26
ifndef RUSTUP_TOOLCHAIN
export RUSTUP_TOOLCHAIN := nightly
endif
ifneq ($(skip_rustup_check),1)
ifeq ($(RUSTUP_HOME),)
#$(info RUSTUP_HOME is not defined, trying to find a good default)
ifeq ($(USE_USERPROFILE_AS_HOME),1)
RUSTUP_HOME_X := $(shell cygpath --windows "$(USERPROFILE)\\.cargo")
ifneq ("$(wildcard $(RUSTUP_HOME_X))","")
export RUSTUP_HOME := "$(RUSTUP_HOME_X)"
else
$(info $(RUSTUP_HOME_X) does not exist)
endif
RUSTUP_HOME_X :=
else
ifneq ("$(wildcard $(HOME)/.rustup)","")
export RUSTUP_HOME := $(HOME)/.rustup
else
ifneq ("$(wildcard $(HOME)/.cargo)","")
export RUSTUP_HOME := $(HOME)/.cargo
else
$(info $(HOME)/.cargo does not exist)
endif
endif
endif
endif
ifeq ($(UNAME_O),Cygwin)
RUSTUP_HOME := $(shell cygpath --windows $(RUSTUP_HOME))
endif
ifeq ($(RUSTUP_HOME),)
$(warning Could not find rustup home, define RUSTUP_HOME)
export RUSTUP_HOME := $(HOME)/.rustup
$(info $(MAKE) --no-print-directory --environment-overrides --no-builtin-rules rustup-install skip_rustup_check=1 skip_cargo_check=1)
$(shell $(MAKE) --no-print-directory --environment-overrides --no-builtin-rules rustup-install skip_rustup_check=1 skip_cargo_check=1)
endif
ifneq ($(skip_rustup_check),1)
ifneq ("$(wildcard $(HOME)/.cargo/bin/rustup)","")
RUSTUP_BIN := $(HOME)/.cargo/bin/rustup
else
$(warning $(HOME)/.cargo/bin/rustup does not exist, assuming "rustup" instead)
RUSTUP_BIN := rustup
endif
endif
endif
RUSTUP_BIN := $(call where-is-binary,rustup)
# if not found look in the obvious places
ifndef RUSTUP_BIN
ifneq ("$(wildcard $(HOME)/.cargo/bin/rustup)","")
RUSTUP_BIN := $(HOME)/.cargo/bin/rustup
else
ifneq ("$(wildcard $(HOME)/.rustup/bin/rustup)","")
RUSTUP_BIN := $(HOME)/.rustup/bin/rustup
endif
endif
endif
RUSTUP_INIT_BIN := $(call where-is-binary,rustup-init)
# if not found look in the obvious places
ifndef RUSTUP_INIT_BIN
ifneq ("$(wildcard $(HOME)/.cargo/bin/rustup-init)","")
RUSTUP_INIT_BIN := $(HOME)/.cargo/bin/rustup-init
else
ifneq ("$(wildcard $(HOME)/.rustup/bin/rustup-init)","")
RUSTUP_INIT_BIN := $(HOME)/.rustup/bin/rustup-init
else
ifneq ("$(wildcard /opt/homebrew/bin/rustup-init)","")
RUSTUP_INIT_BIN := /opt/homebrew/bin/rustup-init
endif
endif
endif
else
endif
ifneq ($(RUSTUP_BIN),)
RUSTUP_VERSION := $(shell $(RUSTUP_BIN) --version 2>/dev/null | cut -d\ -f2)
endif
ifeq ($(UNAME_O),Windows)
RUSTUP_ALL_TARGETS := $(RUST_TARGET) wasm32-unknown-unknown
RUSTUP_ALL_TARGETS_STABLE := $(RUST_TARGET) wasm32-unknown-unknown
else
ifeq ($(UNAME_O),GNU/Linux)
RUSTUP_ALL_TARGETS := $(RUST_TARGET) wasm32-unknown-unknown $(UNAME_M_rust)-unknown-linux-musl $(UNAME_M)-unknown-linux-gnu
RUSTUP_ALL_TARGETS_STABLE := $(RUST_TARGET) wasm32-unknown-unknown $(UNAME_M_rust)-unknown-linux-musl $(UNAME_M)-unknown-linux-gnu
else
#$(info unrecognized UNAME_O: $(UNAME_O))
RUSTUP_ALL_TARGETS := $(RUST_TARGET) \
wasm32-unknown-unknown \
$(UNAME_M_rust)-unknown-linux-musl \
$(UNAME_M_rust)-unknown-linux-gnu \
aarch64-unknown-linux-gnu \
$(UNAME_M_rust)-apple-darwin
RUSTUP_ALL_TARGETS_STABLE := $(RUST_TARGET) \
wasm32-unknown-unknown \
aarch64-unknown-linux-gnu
endif
endif
#$(info RUSTUP_BIN=$(RUSTUP_BIN))
#$(info RUSTUP_INIT_BIN=$(RUSTUP_INIT_BIN))
#$(info RUSTUP_VERSION=$(RUSTUP_VERSION))
#$(info RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN))
.PHONY: rustup-install
ifdef RUSTUP_BIN
rustup-install: rustup-install-info-before rustup-toolchain-install
endif
ifdef BREW_BIN
rustup-install: rustup-install-info-before rustup-init-install-with-brew rustup-toolchain-install
else
rustup-install: rustup-install-info-before rustup-install-with-curl rustup-toolchain-install
endif
.PHONY: rustup-install-info-before
rustup-install-info-before:
@printf "$(bold)Installing Rust:$(normal)\n"
.PHONY: rustup-init-install-with-brew
ifdef RUSTUP_INIT_BIN
rustup-init-install-with-brew: brew-check
@printf "$(bold)rustup-init-install-with-brew:$(normal)\n"
$(BREW_BIN) install rustup-init
else
rustup-init-install-with-brew: brew-check
@printf "$(bold)rustup-init-install-with-brew:$(normal)\n"
@if ! command -v rustup-init ; then \
echo "Installing rustup-init" ; \
$(BREW_BIN) install rustup-init ; \
if ! command -v rustup-init ; then \
echo "ERROR: Could not find rustup-init" ; \
exit 1 ; \
fi ; \
else \
echo "rustup-init is already installed" ; \
fi
# @rustup-init \
# --quiet -y \
# --no-update-default-toolchain \
# --default-toolchain $(RUSTUP_TOOLCHAIN) \
# --target $(RUSTUP_ALL_TARGETS) \
# --profile default
@echo "****** Rustup, rust, cargo etc. have been installed ******"
endif
.PHONY: rustup-install-with-curl
rustup-install-with-curl: curl-check
@printf "$(bold)rustup-install-with-curl:$(normal)\n"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
--quiet -y \
--no-update-default-toolchain \
--default-toolchain $(RUSTUP_TOOLCHAIN) \
--target $(RUSTUP_ALL_TARGETS) \
--profile default
@echo "****** Rustup, rust, cargo etc. have been installed ******"
.PHONY: rustup-info
ifdef RUSTUP_BIN
rustup-info:
@printf "$(bold)Installed targets:$(normal)\n"
@$(RUSTUP_BIN) target list --installed
@printf "$(bold)Installed toolchains:$(normal)\n"
@$(RUSTUP_BIN) toolchain list
@printf "$(bold)Active toolchain:$(normal)\n"
@$(RUSTUP_BIN) show
else
rustup-info:
endif
.PHONY: rustup-toolchain-install
rustup-toolchain-install: _rustup-toolchain-install-no-info rustup-info
.PHONY: _rustup-toolchain-install-no-info
ifdef RUSTUP_BIN
_rustup-toolchain-install-no-info:
@printf "$(bold)rustup-toolchain-install:$(normal)\n"
@printf "Installing rust via rustup\n"
@if [[ "$(RUSTUP_TOOLCHAIN)" == "stable" ]] ; then \
RUSTUP_INIT_SKIP_PATH_CHECK=yes $(RUSTUP_BIN) toolchain install \
stable \
--target $(RUSTUP_ALL_TARGETS_STABLE) \
--profile default \
--allow-downgrade \
--force-non-host ; \
else \
RUSTUP_INIT_SKIP_PATH_CHECK=yes $(RUSTUP_BIN) toolchain install \
$(RUSTUP_TOOLCHAIN) \
--target $(RUSTUP_ALL_TARGETS) \
--profile default \
--allow-downgrade \
--force-non-host ; \
fi
@$(RUSTUP_BIN) toolchain install \
nightly \
--target $(RUSTUP_ALL_TARGETS) \
--profile default \
--allow-downgrade \
--force-non-host
else
ifdef RUSTUP_INIT_BIN
_rustup-toolchain-install-no-info:
@printf "$(bold)rustup-toolchain-install:$(normal)\n"
@printf "Installing rust via rustup-init\n"
@if [[ "$(RUSTUP_TOOLCHAIN)" == "stable" ]] ; then \
RUSTUP_INIT_SKIP_PATH_CHECK=yes $(RUSTUP_INIT_BIN) \
--quiet -y \
--no-update-default-toolchain \
--default-toolchain $(RUSTUP_TOOLCHAIN) \
--target $(RUSTUP_ALL_TARGETS_STABLE) \
--profile default ; \
else \
RUSTUP_INIT_SKIP_PATH_CHECK=yes $(RUSTUP_INIT_BIN) \
--quiet -y \
--no-update-default-toolchain \
--default-toolchain $(RUSTUP_TOOLCHAIN) \
--target $(RUSTUP_ALL_TARGETS) \
--profile default ; \
fi
else
_rustup-toolchain-install-no-info:
$echo "ERROR: rustup-init is not installed, run $(MAKE) rustup-init-install-with-brew"
endif
endif
.PHONY: rustup-check
ifndef RUSTUP_BIN
rustup-check:
else
rustup-check: rustup-install
@$(RUSTUP_BIN) show
endif
.PHONY: rustup-update
rustup-update: rustup-install
$(RUSTUP_BIN) update stable nightly
.PHONY: rustup-check-components
ifeq ($(RUNNING_IN_DOCKER),1)
rustup-check-components:
@echo "Running in docker, skipping rustup-check-components"
else
ifdef RUSTUP_BIN
rustup-check-components: rustup-check
@printf "$(bold)rustup-check-components:$(normal)\n"
@#echo "RUSTUP_TOOLCHAIN=$${RUSTUP_TOOLCHAIN}"
@#echo "RUSTUP_ALL_TARGETS=$${RUSTUP_ALL_TARGETS}"
@printf "Check rustup toolchain and components\nfor default toolchain $(green)$(RUSTUP_TOOLCHAIN)$(normal)\n and targets\n$(green)$(RUSTUP_ALL_TARGETS)$(normal):"
$(RUSTUP_BIN) \
toolchain install $(RUSTUP_TOOLCHAIN) \
--target $(RUSTUP_ALL_TARGETS) \
--component rust-docs rustc rust-std rust-src rustfmt clippy rust-analyzer
else
rustup-check-components:
endif
endif
.PHONY: rustup-nightly
rustup-nightly: rustup-check
@$(RUSTUP_BIN) --quiet override set $(RUSTUP_TOOLCHAIN)
.PHONY: rustup-wasm
ifeq ($(RUNNING_IN_DOCKER),1)
rustup-wasm:
@echo "Running in docker, skipping rustup-wasm"
else
rustup-wasm: rustup-check
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) wasm32-unknown-unknown
endif
.PHONY: rustup-add-targets
ifeq ($(RUNNING_IN_DOCKER),1)
rustup-add-targets:
@echo "Running in docker, skipping rustup-add-targets"
else
rustup-add-targets: rustup-target-add-default rustup-target-add-musl rustup-target-add-wasm rustup-linux-x86-64
endif
.PHONY: rustup-target-add-default
rustup-target-add-default: rustup-check
@echo "Adding rust target: $(RUST_TARGET)"
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) $(RUST_TARGET) 2>/dev/null
.PHONY: rustup-target-add-musl
ifeq ($(UNAME_O),Darwin)
rustup-target-add-musl: rustup-check musl-cross-install
@echo "Adding rust target x86_64-unknown-linux-musl"
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) x86_64-unknown-linux-musl
else
ifeq ($(UNAME_O),GNU/Linux)
rustup-target-add-musl: rustup-check _linux-tool-musl
@echo "Adding rust target x86_64-unknown-linux-musl"
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) x86_64-unknown-linux-musl
else
rustup-target-add-musl: rustup-check
@echo "Not installing x86_64-unknown-linux-musl since we're not running on MacOS or Linux"
endif
endif
.PHONY: rustup-linux-x86-64
ifeq ($(UNAME_O),GNU/Linux)
rustup-linux-x86-64: rustup-check
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) x86_64-unknown-linux-gnu
else
rustup-linux-x86-64:
@echo "Not installing x86_64-linux-gnu since we're not running on Linux"
endif
musl-cross-install: brew-check
@if [ ! -d $(HOMEBREW_CELLAR)/musl-cross/0.9.* ] ; then $(BREW_BIN) install FiloSottile/musl-cross/musl-cross ; else echo "musl-cross 0.9.* is already installed" ; fi
.PHONY: rustup-target-add-wasm
rustup-target-add-wasm: rustup-check
@$(RUSTUP_BIN) --quiet target add --toolchain $(RUSTUP_TOOLCHAIN) wasm32-unknown-unknown
#$(info <--- .make/rustup.mk)
endif # _MK_RUSTUP_MK_