[librsvg] NMake Makefiles: Support ARM64 Windows builds



commit f4f9c90c9eec7408088429dfe3d63a3f2a33cff2
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Jul 9 17:32:37 2020 +0800

    NMake Makefiles: Support ARM64 Windows builds
    
    This adds support to the NMake Makefiles to enable building for ARM64 Windows,
    either via cross-compiling from an x86 or x64 Windows system, or directly on
    an ARM64 Windows system.
    
    For the ARM64 Windows builds, in all cases the Visual Studio and Rust cross-
    compilers are both involved, so we need to generate and call a .bat file on the
    fly, which will help to eliminate the envvars set by Visual Studio (which will
    get into our way) and call cargo with the right arguments, so it is a bit more
    involved getting an ARM64 Windows build done.
    
    By running the test programs, the builds are more or less on par with the
    x86/x64 counterparts of librsvg on Windows.

 win32/README.txt         |  6 +++++
 win32/detectenv-msvc.mak |  4 ++++
 win32/rsvg-rust.mak      | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)
---
diff --git a/win32/README.txt b/win32/README.txt
index e5b15bfc..31d376a7 100644
--- a/win32/README.txt
+++ b/win32/README.txt
@@ -36,6 +36,12 @@ You will also need the following tools:
  if the pkg-config files cannot be found from the default locations that
  pkg-config will look for.
 
+It is now possible to cross-compile librsvg for ARM64 Windows using this set of
+NMake Makefiles.  You will need to ensure that the Visual Studio ARM64 cross
+compiler (either for x86 or for amd64) is installed, and you have installed the
+`aarch64-pc-windows-msvc` target (rust-std library) via `rustup`.  Such builds
+can be carried out on a normal x86/x86-64 Windows 7+ or on Windows 10 ARM64.
+
 It is recommended that the dependent libraries are built with the same version
 of Visual Studio that is being used to build librsvg, as far as possible.
 
diff --git a/win32/detectenv-msvc.mak b/win32/detectenv-msvc.mak
index 75462e2e..1207773b 100644
--- a/win32/detectenv-msvc.mak
+++ b/win32/detectenv-msvc.mak
@@ -21,6 +21,8 @@ _HASH=^#
     && ![echo PLAT=Win32 >> vercl.x] \
     && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
     && ![echo PLAT=x64 >> vercl.x] \
+    && ![echo $(_HASH)elif defined(_M_ARM64) >> vercl.x] \
+    && ![echo PLAT=arm64 >> vercl.x] \
     && ![echo $(_HASH)endif >> vercl.x] \
     && ![cl -nologo -TC -P vercl.x $(ERRNUL)]
 !include vercl.i
@@ -73,6 +75,8 @@ CFLAGS_BASE = /W3 /Zi
 
 !if "$(PLAT)" == "x64"
 LDFLAGS_ARCH = /machine:x64
+!elseif "$(PLAT)" == "arm64"
+LDFLAGS_ARCH = /machine:arm64
 !else
 LDFLAGS_ARCH = /machine:x86
 !endif
diff --git a/win32/rsvg-rust.mak b/win32/rsvg-rust.mak
index 68a5ca6d..19329a35 100644
--- a/win32/rsvg-rust.mak
+++ b/win32/rsvg-rust.mak
@@ -15,6 +15,8 @@ RUSTUP = rustup
 
 !if "$(PLAT)" == "x64"
 RUST_TARGET = x86_64
+!elseif "$(PLAT)" == "arm64"
+RUST_TARGET = aarch64
 !else
 RUST_TARGET = i686
 !endif
@@ -37,6 +39,64 @@ CARGO_CMD = $(CARGO) build $(CARGO_TARGET) --release
 CARGO_CMD = $(CARGO) build $(CARGO_TARGET)
 !endif
 
+# For building the Rust bits for ARM64 Windows, we need to use a cross compiler,
+# and it requires us to set up a default cmd.exe environment without any of the
+# MSVC envvars, except the absolutely necessary ones.  So, we need to put those
+# and the calls to cargo and therefore rustc in a temporary .bat file and use
+# 'start /i ...' to call that .bat file
+!if "$(PLAT)" == "arm64"
+build-arm64-$(CFG).bat:
+       @echo @echo off>$@
+       @echo set CommandPromptType=>>$@
+       @echo set DevEnvDir=>>$@
+       @echo set MAKEDIR=>>$@
+       @echo set MAKEFLAGS=>>$@
+       @echo set Platform=>>$@
+       @echo set VCIDEInstallDir=>>$@
+       @echo set VCINSTALLDIR=>>$@
+       @echo set VCToolsInstallDir=>>$@
+       @echo set VCToolsRedistDir=>>$@
+       @echo set VCToolsVersion=>>$@
+       @echo set VisualStudioVersion=>>$@
+       @echo set VS140COMNTOOLS=>>$@
+       @echo set VS150COMNTOOLS=>>$@
+       @echo set VS160COMNTOOLS=>>$@
+       @echo set VSCMD_ARG_app_plat=>>$@
+       @echo set VSCMD_VER=>>$@
+       @echo set VSINSTALLDIR=>>$@
+       @echo set WindowsLibPath=>>$@
+       @echo set WindowsSdkBinPath=>>$@
+       @echo set WindowsSdkDir=>>$@
+       @echo set WindowsSDKLibVersion=>>$@
+       @echo set WindowsSdkVerBinPath=>>$@
+       @echo set WindowsSDKVersion=>>$@
+       @echo set Windows_ExecutablePath_x86=>>$@
+       @echo set Windows_ExecutablePath_x64=>>$@
+       @echo set _NMAKE_VER=>>$@
+       @echo set __DOTNET_ADD_64BIT=>>$@
+       @echo set __DOTNET_ADD_32BIT=>>$@
+       @echo set __DOTNET_PREFERRED_BITNESS=>>$@
+       @echo set __VSCMD_PREINIT_VCToolsVersion=>>$@
+       @echo set __VSCMD_PREINIT_VS160COMNTOOLS=>>$@
+       @echo set __VSCMD_script_err_count=>>$@
+       @echo if not "$(__VSCMD_PREINIT_PATH)" == "" set 
PATH=$(__VSCMD_PREINIT_PATH);%HOMEPATH%\.cargo\bin>>$@
+       @echo if "$(__VSCMD_PREINIT_PATH)" == "" set 
PATH=c:\Windows\system;c:\Windows;c:\Windows\system32\wbem;%HOMEPATH%\.cargo\bin>>$@
+       @echo set CARGO_TARGET_DIR=win32\vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api>>$@
+       @echo set GTK_LIB_DIR=$(LIBDIR)>>$@
+       @echo cd ..>>$@
+       @echo $(CARGO_CMD) --verbose>>$@
+
+vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api\$(RUST_TARGET)-pc-windows-msvc\$(CFG)\rsvg_c_api.lib: 
build-arm64-$(CFG).bat
+       @echo Please do not manually close the command window that pops up...
+       @echo.
+       @echo If this fails due to LNK1112 or a linker executable cannot be found, run
+       @echo 'nmake /f Makefile CFG=$(CFG) PREFIX=$(PREFIX) $**',
+       @echo and then run 'start /i /wait cmd /c $**', and then continue
+       @echo the build with your original NMake command line.
+       @start "Building the Rust bits for ARM64 Windows MSVC Build, please do not close this console 
window..." /wait /i cmd /c $**
+       @del /f/q $**
+
+!else
 vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api\$(RUST_TARGET)-pc-windows-msvc\$(CFG)\rsvg_c_api.lib:
        @set PATH=%PATH%;%HOMEPATH%\.cargo\bin
        @set CARGO_TARGET_DIR=win32\vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api
@@ -47,10 +107,12 @@ vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api\$(RUST_TARGET)-pc-windows-msvc\$(CFG)\r
        @cd win32
        @set GTK_LIB_DIR=
        @set CARGO_TARGET_DIR=
+!endif
 
 cargo-clean:
        @set PATH=%PATH%;%HOMEPATH%\.cargo\bin
        @set CARGO_TARGET_DIR=win32\vs$(VSVER)\$(CFG)\$(PLAT)\obj\rsvg_c_api
+       @if exist build-arm64-$(CFG).bat del /f/q build-arm64-$(CFG).bat
        @cd ..
        @$(CARGO) clean
        @cd win32


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]