Skip to content

Commit c292204

Browse files
author
Marge Bot
committed
Merge branch 'msvc-default-rust' into 'main'
NMake Makefiles: Default to using the default Rust toolchain See merge request GNOME/librsvg!840
2 parents 352b27e + 9ed825b commit c292204

File tree

5 files changed

+116
-45
lines changed

5 files changed

+116
-45
lines changed

win32/MSVC-Builds.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,18 @@ dependencies:
2424

2525
You will also need the following tools:
2626
* Visual Studio 2013 or later, with C/C++ compilation support (MSVC).
27-
* The Rust Compiler and tools with the msvc toolchain(s) installed, that
28-
matches the architecture that is being built. It is recommended to use
29-
the `rustup` tool from https://www.rust-lang.org/ to install and
30-
configure Rust, which will install Rust in `%HOMEPATH%\.cargo` by
31-
default.
27+
* The Rust Compiler and tools with the msvc toolchain(s) and/or target(s)
28+
installed, that matches the architecture that is being built. It is
29+
recommended to use the `rustup` tool from https://www.rust-lang.org/
30+
to install and configure Rust, which will install Rust in
31+
`%HOMEPATH%\.cargo` by default, which will be the default location that
32+
is looked up for the `rustup` and `cargo` tools. If no `TOOLCHAIN_VERSION`
33+
is specified (or if you are carrying out a cross-build), you need to
34+
ensure that you added the target architecture to your default toolchain
35+
via `rustup` if the architecture differs from the toolchain's architure.
36+
If `TOOLCHAIN_VERSION` is specified and a cross-build is not carried out,
37+
you will need to ensure the corresponding toolchain for the target
38+
architecture is installed.
3239
* `pkg-config` tool (or something that is compatible, set via
3340
`PKG_CONFIG` in the NMake command line if cross-compiling, or if in a
3441
non-standard location). `PKG_CONFIG_PATH` in the NMake command line is
@@ -168,12 +175,10 @@ Where:
168175
that HarfBuzz, FontConfig and FreeType will also be required for
169176
the test programs to run.
170177
* `VERBOSE`: Use verbose mode when building the Rust code.
171-
* `USE_NIGHTLY_TOOLCHAIN`, `TOOLCHAIN_VERSION=<Rust_toolchain_version>`:
172-
Use a nightly (unstable) Rust toolchain or an installed previous-stable
173-
version of the Rust toolchain instead of the latest stable toolchain,
174-
which is the default. Useful for testing the librsvg code against an
175-
unstable toolchain or the unstable toolchain itself, or if the
176-
latest Rust toolchain release introduced unexpected issues. Note
177-
that `USE_NIGHTLY_TOOLCHAIN` takes precedence over
178-
`TOOLCHAIN_VERSION`, and `TOOLCHAIN_VERSION=nightly` is the same
179-
as `USE_NIGHTLY_TOOLCHAIN=1`
178+
* `TOOLCHAIN_VERSION=<Rust_toolchain_version>`:
179+
Use an specified installed version (or nightly version)
180+
of the Rust toolchain instead of the default toolchain.
181+
Useful for testing the librsvg code against a nightly toolchain
182+
or the unstable toolchain itself, or if the latest Rust toolchain
183+
release (which is often set as the default) introduced unexpected
184+
issues.

win32/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ EXTRA_DIST = \
1515
Makefile.vc \
1616
MSVC-Builds.md \
1717
rsvg-rust.mak \
18+
rust-default-target.bat \
1819
pc_base.py \
1920
replace.py \
2021
rsvgpc.py

win32/info-msvc.mak

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,10 @@ help:
110110
@echo VERBOSE:
111111
@echo Run Cargo (i.e. the Rust compilation) in verbose mode.
112112
@echo.
113-
@echo USE_NIGHTLY_TOOLCHAIN/TOOLCHAIN_VERSION:
114-
@echo Use a nightly Rust toolchain or a specific toolchain version instead of
115-
@echo the latest installed stable one. Notice the nightly toolchain or specified
116-
@echo toolchain version for the target architecture must be installed beforehand.
117-
@echo (note that TOOLCHAIN_VERSION=nightly is the same as USE_NIGHTLY_TOOLCHAIN=1,
118-
@echo and USE_NIGHTLY_TOOLCHAIN takes precedence over TOOLCHAIN_VERSION).
113+
@echo TOOLCHAIN_VERSION:
114+
@echo Use a specific release or nightly toolchain version instead of
115+
@echo the default one. Notice the specified toolchain version
116+
@for the target architecture must be installed beforehand.
119117
@echo ======
120118
@echo.
121119
@echo Other options:

win32/rsvg-rust.mak

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,41 @@ LIBDIR=$(PREFIX)\lib
66
!endif
77

88
!if "$(CARGO)" == ""
9-
CARGO = cargo
9+
CARGO = %HOMEPATH%\.cargo\bin\cargo
1010
!endif
1111

1212
!if "$(RUSTUP)" == ""
13-
RUSTUP = rustup
13+
RUSTUP = %HOMEPATH%\.cargo\bin\rustup
1414
!endif
1515

16-
# For those who wish to use the nightly toolchain or a particular
17-
# toolchain version to build librsvg
18-
!ifdef USE_NIGHTLY_TOOLCHAIN
19-
TOOLCHAIN_TYPE = nightly
20-
!elseif defined(TOOLCHAIN_VERSION)
16+
!if [call rust-default-target.bat $(RUSTUP)]
17+
!endif
18+
!include rust-cfg.mak
19+
!if [del /f/q rust-cfg.mak]
20+
!endif
21+
22+
# For those who wish to use a particular toolchain version to build librsvg
23+
!if defined(TOOLCHAIN_VERSION)
2124
TOOLCHAIN_TYPE = $(TOOLCHAIN_VERSION)
2225
!else
23-
TOOLCHAIN_TYPE = stable
26+
TOOLCHAIN_TYPE =
27+
!endif
28+
29+
!if "$(TOOLCHAIN_TYPE)" == ""
30+
!if "$(RUST_DEFAULT_COMPILER)" != "pc-windows-msvc"
31+
!error The default Rust toolchain is not an MSVC toolchain. Please use `rustup` to set the default to an MSVC toolchain
32+
!endif
33+
TOOLCHAIN_TYPE = $(RUST_DEFAULT_CHANNEL)
34+
BUILD_HOST = $(RUST_DEFAULT_TARGET)
35+
# non-default toolchain requested
36+
!else
37+
!if "$(PROCESSOR_ARCHITECTURE)" == "x64" || "$(PROCESSOR_ARCHITECTURE)" == "X64" || "$(PROCESSOR_ARCHITECTURE)" == "AMD64"
38+
BUILD_HOST = x64
39+
!elseif "$(PROCESSOR_ARCHITECTURE)" == "ARM64"
40+
BUILD_HOST = arm64
41+
!elseif "$(PROCESSOR_ARCHITECTURE)" == "x86"
42+
BUILD_HOST = Win32
43+
!endif
2444
!endif
2545

2646
!ifdef VERBOSE
@@ -32,26 +52,37 @@ RUST_VERBOSE_FLAG = --verbose
3252
FORCE_CROSS = 0
3353
!endif
3454

55+
# Setup cross builds if needed
3556
!if "$(PLAT)" == "x64"
3657
RUST_TARGET = x86_64
37-
!if "$(PROCESSOR_ARCHITECTURE)" == "ARM64"
58+
!if "$(BUILD_HOST)" != "$(PLAT)"
3859
FORCE_CROSS = 1
60+
!if "$(BUILD_HOST)" == "arm64"
3961
RUST_HOST = aarch64
40-
!elseif "$(PROCESSOR_ARCHITECTURE)" == "x86"
41-
FORCE_CROSS = 1
62+
!elseif "$(BUILD_HOST)" == "Win32"
4263
RUST_HOST = i686
4364
!endif
65+
!endif
4466
!elseif "$(PLAT)" == "arm64"
4567
RUST_TARGET = aarch64
46-
!if "$(PROCESSOR_ARCHITECTURE)" == "x64" || "$(PROCESSOR_ARCHITECTURE)" == "X64" || "$(PROCESSOR_ARCHITECTURE)" == "AMD64"
68+
!if "$(BUILD_HOST)" != "$(PLAT)"
4769
FORCE_CROSS = 1
70+
!if "$(BUILD_HOST)" == "x64"
4871
RUST_HOST = x86_64
49-
!elseif "$(PROCESSOR_ARCHITECTURE)" == "x86"
50-
FORCE_CROSS = 1
72+
!elseif "$(BUILD_HOST)" == "Win32"
5173
RUST_HOST = i686
5274
!endif
75+
!endif
5376
!else
5477
RUST_TARGET = i686
78+
!if "$(BUILD_HOST)" != "$(PLAT)"
79+
FORCE_CROSS = 1
80+
!if "$(BUILD_HOST)" == "arm64"
81+
RUST_HOST = aarch64
82+
!elseif "$(BUILD_HOST)" == "x64"
83+
RUST_HOST = x86_64
84+
!endif
85+
!endif
5586
!endif
5687

5788
!if "$(VALID_CFGSET)" == "TRUE"
@@ -63,21 +94,23 @@ BUILD_RUST = 0
6394
!if "$(BUILD_RUST)" == "1"
6495

6596
CARGO_TARGET = $(RUST_TARGET)-pc-windows-msvc
66-
CARGO_TARGET_CMD = --target $(CARGO_TARGET)
67-
CARGO_TARGET_TOOLCHAIN = $(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
97+
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
98+
6899
RUSTUP_CMD = $(RUSTUP) default $(DEFAULT_TARGET)
69100
CARGO_TARGET_DIR = vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api
70101
CARGO_TARGET_DIR_FLAG = --target-dir=$(CARGO_TARGET_DIR)
71102

72103
MANIFEST_PATH_FLAG = --manifest-path=..\Cargo.toml
73104
!if $(FORCE_CROSS) > 0
74-
RUST_HOST_TOOLCHAIN = $(TOOLCHAIN_TYPE)-$(RUST_HOST)-pc-windows-msvc
75-
CARGO_CMD = $(CARGO) +$(RUST_HOST_TOOLCHAIN) --locked build $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
76-
CARGO_CLEAN_CMD = $(CARGO) +$(RUST_HOST_TOOLCHAIN) clean $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
105+
RUST_HOST_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(RUST_HOST)-pc-windows-msvc
106+
107+
CARGO_TARGET_CMD = --target $(CARGO_TARGET)
108+
CARGO_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) --locked build $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
109+
CARGO_CLEAN_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) clean $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
77110
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CARGO_TARGET)\$(CFG)
78111
!else
79-
CARGO_CMD = $(CARGO) +$(CARGO_TARGET_TOOLCHAIN) --locked build $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
80-
CARGO_CLEAN_CMD = $(CARGO) +$(CARGO_TARGET_TOOLCHAIN) clean $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
112+
CARGO_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) --locked build $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
113+
CARGO_CLEAN_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) clean $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
81114
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CFG)
82115
!endif
83116
!if "$(CFG)" == "release" || "$(CFG)" == "Release"
@@ -125,8 +158,8 @@ build-$(PLAT)-$(CFG).pre.bat:
125158
@echo set __VSCMD_PREINIT_VCToolsVersion=>>$@
126159
@echo set __VSCMD_PREINIT_VS160COMNTOOLS=>>$@
127160
@echo set __VSCMD_script_err_count=>>$@
128-
@echo if not "$(__VSCMD_PREINIT_PATH)" == "" set PATH=$(__VSCMD_PREINIT_PATH);%HOMEPATH%\.cargo\bin>>$@
129-
@echo if "$(__VSCMD_PREINIT_PATH)" == "" set PATH=c:\Windows\system;c:\Windows;c:\Windows\system32\wbem;%HOMEPATH%\.cargo\bin>>$@
161+
@echo if not "$(__VSCMD_PREINIT_PATH)" == "" set PATH=$(__VSCMD_PREINIT_PATH)>>$@
162+
@echo if "$(__VSCMD_PREINIT_PATH)" == "" set PATH=c:\Windows\system;c:\Windows;c:\Windows\system32\wbem>>$@
130163
@echo set GTK_LIB_DIR=$(LIBDIR)>>$@
131164
@echo set SYSTEM_DEPS_FREETYPE2_NO_PKG_CONFIG=1 >>$@
132165
@echo set SYSTEM_DEPS_FREETYPE2_LIB=$(FREETYPE_LIB:.lib=)>>$@
@@ -170,7 +203,6 @@ $(RSVG_INTERNAL_LIB):
170203
@set GTK_LIB_DIR=
171204

172205
$(CARGO_TARGET_OUTPUT_DIR)\rsvg-convert.exe:
173-
@set PATH=%PATH%;%HOMEPATH%\.cargo\bin
174206
@set GTK_LIB_DIR=$(LIBDIR);$(LIB)
175207
@set SYSTEM_DEPS_FREETYPE2_NO_PKG_CONFIG=1
176208
@set SYSTEM_DEPS_FREETYPE2_LIB=$(FREETYPE_LIB:.lib=)
@@ -183,7 +215,6 @@ $(CARGO_TARGET_OUTPUT_DIR)\rsvg-convert.exe:
183215
!endif
184216

185217
cargo-clean:
186-
@set PATH=%PATH%;%HOMEPATH%\.cargo\bin
187218
@if exist build-$(PLAT)-$(CFG).bat del /f/q build-$(PLAT)-$(CFG).bat
188219
@$(CARGO_CLEAN_CMD)
189220

win32/rust-default-target.bat

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@echo off
2+
:: SETLOCAL ENABLEDELAYEDEXPANSION
3+
set RUSTUP=%1
4+
5+
FOR /F "tokens=* USEBACKQ" %%F IN (`%RUSTUP% default`) DO (
6+
SET RUST_DEFAULT_TOOLCHAIN=%%F
7+
)
8+
9+
:: We want to be very sure that if we are using the default
10+
:: Rust toolchain for the build, we are indeed using an msvc
11+
:: one!
12+
13+
FOR /F "tokens=1,2,3,4,5* delims=-" %%a IN ("%RUST_DEFAULT_TOOLCHAIN%") do (
14+
:: <version>-<platform>-pc-windows-msvc (default) or stable-<platform>-pc-windows-msvc (default)
15+
if not "%%a" == "nightly" set CHANNEL=%%a
16+
if not "%%a" == "nightly" set TARGET=%%b
17+
if not "%%a" == "nightly" FOR /F "tokens=1,2 delims= " %%o IN ("%%e") do (
18+
set TOOLCHAIN_COMPILER=%%c-%%d-%%o
19+
)
20+
21+
:: nightly-yyyy-mm-dd-<platform>-pc-windows-msvc (default)
22+
if "%%a" == "nightly" set CHANNEL=%%a-%%b-%%c
23+
if "%%a" == "nightly" set TARGET=%%e
24+
if "%%a" == "nightly" FOR /F "tokens=1,2 delims= " %%o IN ("%%f") do (
25+
set TOOLCHAIN_COMPILER=%%o
26+
)
27+
)
28+
29+
if "%TARGET%" == "aarch64" set NMAKE_TGT=amd64
30+
if "%TARGET%" == "x86_64" set NMAKE_TGT=x64
31+
if "%TARGET%" == "i686" set NMAKE_TGT=Win32
32+
33+
if exist rust-cfg.mak goto :EOF
34+
echo RUST_DEFAULT_CHANNEL=%CHANNEL%>>rust-cfg.mak
35+
echo RUST_DEFAULT_TARGET=%NMAKE_TGT%>>rust-cfg.mak
36+
echo RUST_DEFAULT_COMPILER=%TOOLCHAIN_COMPILER%>>rust-cfg.mak

0 commit comments

Comments
 (0)