Skip to content

Commit a75cada

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 c292204 commit a75cada

File tree

6 files changed

+108
-76
lines changed

6 files changed

+108
-76
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
@@ -116,12 +116,7 @@ LIBRSVG_DEP_LIBS = \
116116
$(LIBRSVG_EXTRA_DEP_LIBS) \
117117
pango-1.0.lib \
118118
cairo-gobject.lib \
119-
$(BASE_DEP_LIBS) \
120-
libxml2.lib \
121-
advapi32.lib \
122-
userenv.lib \
123-
bcrypt.lib \
124-
ws2_32.lib
119+
$(BASE_DEP_LIBS)
125120

126121
RSVG_PIXBUF_LOADER_CFLAGS = \
127122
$(BASE_CFLAGS) \

win32/rsvg-rust.mak

Lines changed: 26 additions & 32 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+
RUST_HOST = $(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+
RUST_HOST = x86_64
3940
!elseif "$(PROCESSOR_ARCHITECTURE)" == "ARM64"
4041
BUILD_HOST = arm64
42+
RUST_HOST = aarch64
4143
!elseif "$(PROCESSOR_ARCHITECTURE)" == "x86"
4244
BUILD_HOST = Win32
45+
RUST_HOST = i686
4346
!endif
4447
!endif
4548

@@ -55,34 +58,13 @@ FORCE_CROSS = 0
5558
# Setup cross builds if needed
5659
!if "$(PLAT)" == "x64"
5760
RUST_TARGET = x86_64
58-
!if "$(BUILD_HOST)" != "$(PLAT)"
59-
FORCE_CROSS = 1
60-
!if "$(BUILD_HOST)" == "arm64"
61-
RUST_HOST = aarch64
62-
!elseif "$(BUILD_HOST)" == "Win32"
63-
RUST_HOST = i686
64-
!endif
65-
!endif
6661
!elseif "$(PLAT)" == "arm64"
6762
RUST_TARGET = aarch64
68-
!if "$(BUILD_HOST)" != "$(PLAT)"
69-
FORCE_CROSS = 1
70-
!if "$(BUILD_HOST)" == "x64"
71-
RUST_HOST = x86_64
72-
!elseif "$(BUILD_HOST)" == "Win32"
73-
RUST_HOST = i686
74-
!endif
75-
!endif
7663
!else
7764
RUST_TARGET = i686
65+
!endif
7866
!if "$(BUILD_HOST)" != "$(PLAT)"
7967
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
8668
!endif
8769

8870
!if "$(VALID_CFGSET)" == "TRUE"
@@ -92,11 +74,8 @@ BUILD_RUST = 0
9274
!endif
9375

9476
!if "$(BUILD_RUST)" == "1"
95-
9677
CARGO_TARGET = $(RUST_TARGET)-pc-windows-msvc
97-
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
9878

99-
RUSTUP_CMD = $(RUSTUP) default $(DEFAULT_TARGET)
10079
CARGO_TARGET_DIR = vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api
10180
CARGO_TARGET_DIR_FLAG = --target-dir=$(CARGO_TARGET_DIR)
10281

@@ -109,10 +88,25 @@ CARGO_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) --locked build $(CARGO_TARGET_CMD) $
10988
CARGO_CLEAN_CMD = $(CARGO) $(RUST_HOST_TOOLCHAIN) clean $(CARGO_TARGET_CMD) $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
11089
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CARGO_TARGET)\$(CFG)
11190
!else
91+
CARGO_TARGET_TOOLCHAIN = +$(TOOLCHAIN_TYPE)-$(CARGO_TARGET)
92+
11293
CARGO_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) --locked build $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
11394
CARGO_CLEAN_CMD = $(CARGO) $(CARGO_TARGET_TOOLCHAIN) clean $(MANIFEST_PATH_FLAG) $(CARGO_TARGET_DIR_FLAG)
11495
CARGO_TARGET_OUTPUT_DIR = $(CARGO_TARGET_DIR)\$(CFG)
11596
!endif
97+
98+
# Query the system libs that we will be using to link the librsvg DLL
99+
!if $(FORCE_CROSS) > 0
100+
!if [call rust-query-cfg.bat check-syslibs $(RUSTUP) $(RUST_HOST_TOOLCHAIN) $(RUST_TARGET)]
101+
!endif
102+
!else
103+
!if [call rust-query-cfg.bat check-syslibs $(RUSTUP) $(CARGO_TARGET_TOOLCHAIN) $(RUST_TARGET)]
104+
!endif
105+
!endif
106+
!include rust-sys-libs.mak
107+
!if [del /f/q rust-sys-libs.mak]
108+
!endif
109+
116110
!if "$(CFG)" == "release" || "$(CFG)" == "Release"
117111
CARGO_CMD = $(CARGO_CMD) --release
118112
!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)