Skip to content

Commit 8e9bc4f

Browse files
committed
NMake Builds: Fix linking on Rust 1.70.0 or later
Link also to ntdll.lib which became required since Rust 1.70.0 or nightly-2023-03-21 [1] (which was sadly not clearly documented as such) when linking the resulting rsvg DLL. So, we extend the batch script that is used to formerly query the default Rust toolchain to also check whether it requires linking to ntdll.lib by checking against the Rust version. [1]: rust-lang/rust#108262 Fixes issue #968.
1 parent c292204 commit 8e9bc4f

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,17 @@ LIBRSVG_DEP_LIBS = \
117117
pango-1.0.lib \
118118
cairo-gobject.lib \
119119
$(BASE_DEP_LIBS) \
120-
libxml2.lib \
121120
advapi32.lib \
122121
userenv.lib \
123122
bcrypt.lib \
124123
ws2_32.lib
125124

125+
LIBRSVG_SYSTEM_DEP_LIBS = \
126+
advapi32.lib \
127+
userenv.lib \
128+
bcrypt.lib \
129+
ws2_32.lib
130+
126131
RSVG_PIXBUF_LOADER_CFLAGS = \
127132
$(BASE_CFLAGS) \
128133
/DGDK_PIXBUF_ENABLE_BACKEND \

win32/rsvg-rust.mak

Lines changed: 17 additions & 6 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,6 +21,18 @@ TOOLCHAIN_TYPE =
2721
!endif
2822

2923
!if "$(TOOLCHAIN_TYPE)" == ""
24+
CHECK_DEFAULT_COMPILER=1
25+
!if [call rust-query-cfg.bat use-rustup $(RUSTUP)]
26+
!endif
27+
!else
28+
!if [call rust-query-cfg.bat set-toolchain $(RUSTUP) $(TOOLCHAIN_VERSION)]
29+
!endif
30+
!endif
31+
!include rust-cfg.mak
32+
!if [del /f/q rust-cfg.mak]
33+
!endif
34+
35+
!ifdef CHECK_DEFAULT_COMPILER
3036
!if "$(RUST_DEFAULT_COMPILER)" != "pc-windows-msvc"
3137
!error The default Rust toolchain is not an MSVC toolchain. Please use `rustup` to set the default to an MSVC toolchain
3238
!endif
@@ -93,6 +99,11 @@ BUILD_RUST = 0
9399

94100
!if "$(BUILD_RUST)" == "1"
95101

102+
# Link to ntdll.lib for Rust 1.70.0+ or nightly-2023-03-21 or later
103+
!if "$(LIBRSVG_USE_NTDLL)" == "1"
104+
LIBRSVG_SYSTEM_DEP_LIBS = $(LIBRSVG_SYSTEM_DEP_LIBS) ntdll.lib
105+
!endif
106+
96107
CARGO_TARGET = $(RUST_TARGET)-pc-windows-msvc
97108
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
98109

win32/rust-default-target.bat renamed to win32/rust-query-cfg.bat

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@echo off
22
:: SETLOCAL ENABLEDELAYEDEXPANSION
3-
set RUSTUP=%1
3+
if not "%1" == "use-rustup" if not "%1" == "set-toolchain" goto :err_badopt
4+
if "%2" == "" goto :err_badopt
5+
6+
set RUSTUP=%2
7+
if "%1" == "set-toolchain" goto :parse_toolchain
48

59
FOR /F "tokens=* USEBACKQ" %%F IN (`%RUSTUP% default`) DO (
610
SET RUST_DEFAULT_TOOLCHAIN=%%F
@@ -10,7 +14,7 @@ SET RUST_DEFAULT_TOOLCHAIN=%%F
1014
:: Rust toolchain for the build, we are indeed using an msvc
1115
:: one!
1216

13-
FOR /F "tokens=1,2,3,4,5* delims=-" %%a IN ("%RUST_DEFAULT_TOOLCHAIN%") do (
17+
FOR /F "tokens=1,2,3,4,5* delims=-" %%a IN ("%RUST_DEFAULT_TOOLCHAIN%") do (
1418
:: <version>-<platform>-pc-windows-msvc (default) or stable-<platform>-pc-windows-msvc (default)
1519
if not "%%a" == "nightly" set CHANNEL=%%a
1620
if not "%%a" == "nightly" set TARGET=%%b
@@ -34,3 +38,31 @@ if exist rust-cfg.mak goto :EOF
3438
echo RUST_DEFAULT_CHANNEL=%CHANNEL%>>rust-cfg.mak
3539
echo RUST_DEFAULT_TARGET=%NMAKE_TGT%>>rust-cfg.mak
3640
echo RUST_DEFAULT_COMPILER=%TOOLCHAIN_COMPILER%>>rust-cfg.mak
41+
goto :check_link_ntdll
42+
43+
:parse_toolchain
44+
if "%3" == "" goto :err_badopt
45+
set CHANNEL=%3
46+
47+
:check_link_ntdll
48+
FOR /F "tokens=1* delims=-" %%a IN ("%CHANNEL%") do (
49+
set CHANNEL_TYPE=%%a
50+
set NIGHTLY_DATE=%%b
51+
)
52+
53+
if "%CHANNEL_TYPE%" == "stable" FOR /F "tokens=1,2* delims= " %%o in ('%RUSTUP:rustup=rustc% --version') do (
54+
set CHANNEL_TYPE=%%p
55+
)
56+
echo LIBRSVG_USE_NTDLL=1 >> rust-cfg.mak
57+
if not "%CHANNEL_TYPE%" == "nightly" (
58+
if "%CHANNEL_TYPE%" GEQ "1.70.0" echo LIBRSVG_USE_NTDLL=1 >> rust-cfg.mak
59+
if "%CHANNEL_TYPE%" LSS "1.70.0" echo LIBRSVG_USE_NTDLL=0 >> rust-cfg.mak
60+
)
61+
if "%CHANNEL_TYPE%" == "nightly" (
62+
if "%NIGHTLY_DATE%" GEQ "2023-03-21" echo LIBRSVG_USE_NTDLL=1 >> rust-cfg.mak
63+
if "%NIGHTLY_DATE%" LSS "2023-03-21" echo LIBRSVG_USE_NTDLL=0 >> rust-cfg.mak
64+
)
65+
goto :EOF
66+
67+
:err_badopt
68+
echo Usage: %0 [use-rustup^|set-toolchain] rustup-executable] ^<toolchain-version-for-set-toolchain^>

0 commit comments

Comments
 (0)