Skip to content

Commit f4b8055

Browse files
committed
NMake Builds: Use rustc to query the required system libs
Extend the helper batch file that we use to query the default Rust toolchain so that we can use the rustc that corresponds to the Rust toolchain that we are using to query the system libraries (i.e. from the Windows SDK), in order to ensure that the final librvg DLL links, as Rust might involve changes that require more system libraries to be required for the build, such as in issue [1]: rust-lang/rust#108262 Fixes issue #968.
1 parent 561dede commit f4b8055

6 files changed

+107
-54
lines changed

win32/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ EXTRA_DIST = \
1515
Makefile.vc \
1616
MSVC-Builds.md \
1717
rsvg-rust.mak \
18-
rust-default-target.bat \
18+
rust-query-cfg.bat \
1919
pc_base.py \
2020
replace.py \
2121
rsvgpc.py

win32/build-rules-msvc.mak

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ $(LIBRSVG_LIB): $(LIBRSVG_DLL)
4242
# $(dependent_objects)
4343
# <<
4444
# @-if exist [email protected] mt /manifest [email protected] /outputresource:$@;2
45+
4546
$(LIBRSVG_DLL): $(RSVG_INTERNAL_LIB) $(librsvg_OBJS) $(LIBRSVG_DEF)
46-
link /DLL $(LDFLAGS) $(LIBRSVG_DEP_LIBS) \
47+
link /DLL $(LDFLAGS) $(LIBRSVG_DEP_LIBS) $(LIBRSVG_SYSTEM_DEP_LIBS) \
4748
/implib:$(LIBRSVG_LIB) \
4849
-out:$@ /def:$(LIBRSVG_DEF) @<<
4950
$(librsvg_OBJS)

win32/config-msvc.mak.in

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,7 @@ LIBRSVG_DEP_LIBS = \
114114
$(LIBRSVG_EXTRA_DEP_LIBS) \
115115
pango-1.0.lib \
116116
cairo-gobject.lib \
117-
$(BASE_DEP_LIBS) \
118-
libxml2.lib \
119-
advapi32.lib \
120-
userenv.lib \
121-
bcrypt.lib \
122-
ws2_32.lib
117+
$(BASE_DEP_LIBS)
123118

124119
RSVG_PIXBUF_LOADER_CFLAGS = \
125120
$(BASE_CFLAGS) \

win32/rsvg-rust.mak

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ CARGO = %HOMEPATH%\.cargo\bin\cargo
1313
RUSTUP = %HOMEPATH%\.cargo\bin\rustup
1414
!endif
1515

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-
2216
# For those who wish to use a particular toolchain version to build librsvg
2317
!if defined(TOOLCHAIN_VERSION)
2418
TOOLCHAIN_TYPE = $(TOOLCHAIN_VERSION)
@@ -27,19 +21,28 @@ TOOLCHAIN_TYPE =
2721
!endif
2822

2923
!if "$(TOOLCHAIN_TYPE)" == ""
24+
!if [call rust-query-cfg.bat use-rustup $(RUSTUP)]
25+
!endif
26+
!include rust-cfg.mak
27+
!if [del /f/q rust-cfg.mak]
28+
!endif
3029
!if "$(RUST_DEFAULT_COMPILER)" != "pc-windows-msvc"
3130
!error The default Rust toolchain is not an MSVC toolchain. Please use `rustup` to set the default to an MSVC toolchain
3231
!endif
3332
TOOLCHAIN_TYPE = $(RUST_DEFAULT_CHANNEL)
34-
BUILD_HOST = $(RUST_DEFAULT_TARGET)
33+
BUILD_HOST = $(RUST_DEFAULT_MSVC_TARGET)
34+
BUILD_HOST_RUST = $(RUST_DEFAULT_TARGET)
3535
# non-default toolchain requested
3636
!else
3737
!if "$(PROCESSOR_ARCHITECTURE)" == "x64" || "$(PROCESSOR_ARCHITECTURE)" == "X64" || "$(PROCESSOR_ARCHITECTURE)" == "AMD64"
3838
BUILD_HOST = x64
39+
BUILD_HOST_RUST = x86_64
3940
!elseif "$(PROCESSOR_ARCHITECTURE)" == "ARM64"
4041
BUILD_HOST = arm64
42+
BUILD_HOST_RUST = aarch64
4143
!elseif "$(PROCESSOR_ARCHITECTURE)" == "x86"
4244
BUILD_HOST = Win32
45+
BUILD_HOST_RUST = i686
4346
!endif
4447
!endif
4548

@@ -92,11 +95,8 @@ BUILD_RUST = 0
9295
!endif
9396

9497
!if "$(BUILD_RUST)" == "1"
95-
9698
CARGO_TARGET = $(RUST_TARGET)-pc-windows-msvc
97-
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
9899

99-
RUSTUP_CMD = $(RUSTUP) default $(DEFAULT_TARGET)
100100
CARGO_TARGET_DIR = vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api
101101
CARGO_TARGET_DIR_FLAG = --target-dir=$(CARGO_TARGET_DIR)
102102

@@ -109,10 +109,25 @@ CARGO_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) --locked build $(CARGO_TARGET_CMD) $
109109
CARGO_CLEAN_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) clean $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
110110
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CARGO_TARGET)\$(CFG)
111111
!else
112+
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
113+
112114
CARGO_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) --locked build $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
113115
CARGO_CLEAN_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) clean $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
114116
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CFG)
115117
!endif
118+
119+
# Query the system libs that we will be using to link the librsvg DLL
120+
!if $(FORCE_CROSS) > 0
121+
!if [call rust-query-cfg.bat check-syslibs $(RUSTUP) $(RUST_HOST_TOOLCHAIN) $(RUST_TARGET)]
122+
!endif
123+
!else
124+
!if [call rust-query-cfg.bat check-syslibs $(RUSTUP) $(CARGO_TARGET_TOOLCHAIN) $(RUST_TARGET)]
125+
!endif
126+
!endif
127+
!include rust-sys-libs.mak
128+
!if [del /f/q rust-sys-libs.mak]
129+
!endif
130+
116131
!if "$(CFG)" == "release" || "$(CFG)" == "Release"
117132
CARGO_CMD = $(CARGO_CMD) --release
118133
!endif

win32/rust-default-target.bat

Lines changed: 0 additions & 36 deletions
This file was deleted.

win32/rust-query-cfg.bat

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@echo off
2+
if not "%1" == "use-rustup" if not "%1" == "check-syslibs" goto :err_badopt
3+
if "%2" == "" goto :err_badopt
4+
5+
set RUSTUP=%2
6+
if "%1" == "check-syslibs" goto :check_syslibs
7+
8+
FOR /F "tokens=* USEBACKQ" %%F IN (`%RUSTUP% default`) DO (
9+
SET RUST_DEFAULT_TOOLCHAIN=%%F
10+
)
11+
12+
:: We want to be very sure that if we are using the default
13+
:: Rust toolchain for the build, we are indeed using an msvc
14+
:: one!
15+
16+
FOR /F "tokens=1,2,3,4,5* delims=-" %%a IN ("%RUST_DEFAULT_TOOLCHAIN%") do (
17+
:: <version>-<platform>-pc-windows-msvc (default) or stable-<platform>-pc-windows-msvc (default)
18+
if not "%%a" == "nightly" set CHANNEL=%%a
19+
if not "%%a" == "nightly" set TARGET=%%b
20+
if not "%%a" == "nightly" FOR /F "tokens=1,2 delims= " %%o IN ("%%e") do (
21+
set TOOLCHAIN_COMPILER=%%c-%%d-%%o
22+
)
23+
24+
:: nightly-yyyy-mm-dd-<platform>-pc-windows-msvc (default)
25+
if "%%a" == "nightly" set CHANNEL=%%a-%%b-%%c
26+
if "%%a" == "nightly" set TARGET=%%e
27+
if "%%a" == "nightly" FOR /F "tokens=1,2 delims= " %%o IN ("%%f") do (
28+
set TOOLCHAIN_COMPILER=%%o
29+
)
30+
)
31+
32+
if "%TARGET%" == "aarch64" set NMAKE_TGT=amd64
33+
if "%TARGET%" == "x86_64" set NMAKE_TGT=x64
34+
if "%TARGET%" == "i686" set NMAKE_TGT=Win32
35+
36+
if exist rust-cfg.mak goto :EOF
37+
echo RUST_DEFAULT_CHANNEL=%CHANNEL%>>rust-cfg.mak
38+
echo RUST_DEFAULT_TARGET=%TARGET%>>rust-cfg.mak
39+
echo RUST_DEFAULT_MSVC_TARGET=%NMAKE_TGT%>>rust-cfg.mak
40+
echo RUST_DEFAULT_COMPILER=%TOOLCHAIN_COMPILER%>>rust-cfg.mak
41+
goto :EOF
42+
43+
:check_syslibs
44+
if "%3" == "" goto :err_badopt
45+
if "%4" == "" goto :err_badopt
46+
if not "%4" == "x86_64" if not "%4" == "aarch64" if not "%4" == "i686" goto :err_badopt
47+
48+
:: grab the results from the following command to extract the needed system
49+
:: libs for linking for Rust builds (this is printed in stderr)
50+
if exist rust-libs.txt goto :check_libs
51+
%RUSTUP:rustup=rustc% %3 --target=%4-pc-windows-msvc ^
52+
--crate-type staticlib --print native-static-libs - < nul 2>>rust-libs.txt
53+
54+
:check_libs
55+
for /f "tokens=1,2*" %%l in ('findstr /ic:"note: native-static-libs:" /b rust-libs.txt') DO (
56+
set ALL_SYS_LIBS=%%n
57+
)
58+
SETLOCAL ENABLEDELAYEDEXPANSION
59+
set LINK_SYS_LIBS=
60+
del /f/q rust-libs.txt
61+
del /f/q rust_out.lib
62+
:: Filter out kernel32.lib, msvcrt.lib and legacy_stdio_definitions.lib
63+
:: they will be pulled in automatically
64+
for %%q in (%ALL_SYS_LIBS%) do (
65+
if not "%%q" == "kernel32.lib" if not "%%q" == "msvcrt.lib" ^
66+
if not "%%q" == "legacy_stdio_definitions.lib" ^
67+
if not "!LINK_SYS_LIBS!" == "" set LINK_SYS_LIBS=!LINK_SYS_LIBS! %%q
68+
69+
if not "%%q" == "kernel32.lib" if not "%%q" == "msvcrt.lib" ^
70+
if not "%%q" == "legacy_stdio_definitions.lib" ^
71+
if "!LINK_SYS_LIBS!" == "" set LINK_SYS_LIBS=%%q
72+
)
73+
74+
echo LIBRSVG_SYSTEM_DEP_LIBS=%LINK_SYS_LIBS%>rust-sys-libs.mak
75+
goto :EOF
76+
77+
:err_badopt
78+
echo Usage: %0 [use-rustup^|check-syslibs] rustup-executable ^<rust-toolchain-for-check-syslibs^> ^<rust-target-platform-for-check-syslibs^>

0 commit comments

Comments
 (0)