Skip to content

CI: Add native Windows arm64 job/package #4931

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/actions/1-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ runs:
run: |
set -eux
cd ..
suffix='win64'
if [[ '${{ inputs.arch }}' == arm64 ]]; then
suffix='woa64'
fi
curl -fL --retry 3 --max-time 300 -o clang.exe \
https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.3/LLVM-20.1.3-win64.exe
https://github.com/llvm/llvm-project/releases/download/llvmorg-20.1.3/LLVM-20.1.3-$suffix.exe
./clang.exe //S # double-slash for bash
rm clang.exe
# C:\Program Files\LLVM\bin should already be in PATH
Expand Down Expand Up @@ -163,7 +167,9 @@ runs:
cd ..

url='https://curl.se/windows/latest.cgi?p=win64-mingw.zip'
if [[ '${{ inputs.arch }}' == x86 ]]; then
if [[ '${{ inputs.arch }}' == arm64 ]]; then
url='https://curl.se/windows/latest.cgi?p=win64a-mingw.zip'
elif [[ '${{ inputs.arch }}' == x86 ]]; then
url='https://curl.se/windows/latest.cgi?p=win32-mingw.zip'
fi

Expand Down
5 changes: 5 additions & 0 deletions .github/actions/5-install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ runs:

cp libcurl/ldc2/* installed/bin/

if [[ '${{ inputs.arch }}' == arm64 ]]; then
echo "No MinGW-based libraries available for arm64 yet."
exit 0
fi

curl -fL --retry 3 --max-time 60 -o mingw-w64-libs.7z \
https://github.com/ldc-developers/mingw-w64-libs/releases/download/v8.0.0/mingw-w64-libs-v8.0.0.7z
mkdir mingw-w64-libs
Expand Down
1 change: 1 addition & 0 deletions .github/actions/merge-windows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ runs:
set PATH=%CD%\ldc2-multilib\lib32;%PATH%
ldc2-multilib\bin\ldc2 -link-defaultlib-shared -m32 -run hello.d || exit /b

# TODO
# preliminary arm64 cross-compilation support
- name: Install ninja v1.12.1
uses: Ahajha/gha-setup-ninja@69595b0cf872acdad8ce599142fbdc88724b9a2b
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ jobs:
-DEXTRA_CXXFLAGS=-flto=full
with_pgo: true

- job_name: Windows arm64
os: windows-11-arm
arch: arm64
base_cmake_flags: >-
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
#extra_cmake_flags: >-
# "-DD_COMPILER_FLAGS=-O -flto=full -defaultlib=phobos2-ldc-lto,druntime-ldc-lto"
# -DEXTRA_CXXFLAGS=-flto=full
#with_pgo: true

- job_name: Windows x86
os: windows-2025
arch: x86
Expand Down
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ if(NOT MSVC_IDE)
endif()

if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "arm64")
message(STATUS "Let D host compiler output arm64 object files")
append("-mtriple=aarch64-windows-msvc" DFLAGS_BASE)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Let D host compiler output 64-bit object files")
append("-m64" DFLAGS_BASE)
else()
Expand Down Expand Up @@ -300,7 +303,9 @@ endif()
if(MSVC)
separate_arguments(LLVM_LDFLAGS WINDOWS_COMMAND "${LLVM_LDFLAGS}")
if(NOT MSVC_IDE) # apparently not needed for VS (and spaces in path are problematic)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
if($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "arm64")
list(APPEND LLVM_LDFLAGS "$ENV{VSINSTALLDIR}DIA SDK\\lib\\arm64\\diaguids.lib")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
list(APPEND LLVM_LDFLAGS "$ENV{VSINSTALLDIR}DIA SDK\\lib\\amd64\\diaguids.lib")
else()
list(APPEND LLVM_LDFLAGS "$ENV{VSINSTALLDIR}DIA SDK\\lib\\diaguids.lib")
Expand Down Expand Up @@ -898,7 +903,9 @@ if (LDC_INSTALL_LLVM_RUNTIME_LIBS)
copy_compilerrt_lib("libclang_rt.xray-profiling${compilerrt_suffix}.a" "libldc_rt.xray-profiling.a" FALSE)
elseif(WIN32)
set(compilerrt_arch_suffix "x86_64")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
if($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "arm64")
set(compilerrt_arch_suffix "aarch64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(compilerrt_arch_suffix "i386")
endif()
if(LDC_LLVM_VER LESS 2000)
Expand Down
7 changes: 5 additions & 2 deletions dmd/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,11 @@ else
reconcileLinkRunLib(params, files.length, target.obj_ext);
version(CRuntime_Microsoft)
{
import dmd.root.longdouble;
initFPU();
version(AArch64) { /* no longdouble_soft support on arm64 host */ } else
{
import dmd.root.longdouble;
initFPU();
}
}
import dmd.root.ctfloat : CTFloat;
CTFloat.initialize();
Expand Down
14 changes: 9 additions & 5 deletions dmd/root/ctfloat.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ private
{
version(CRuntime_DigitalMars) __gshared extern (C) extern const(char)* __locale_decpoint;

version(CRuntime_Microsoft) extern (C++)
version(CRuntime_Microsoft)
{
public import dmd.root.longdouble : longdouble_soft, ld_sprint;
version(AArch64) { /* 64-bit real_t */ } else
{
version = MSVC_X87;
import dmd.root.longdouble : longdouble_soft, ld_sprint;
version (IN_LLVM) {} else
{
import dmd.root.strtold;
import dmd.root.strtold;
}
}
}
}

Expand Down Expand Up @@ -193,7 +197,7 @@ extern (C++) struct CTFloat
// the implementation of longdouble for MSVC is a struct, so mangling
// doesn't match with the C++ header.
// add a wrapper just for isSNaN as this is the only function called from C++
version(CRuntime_Microsoft) static if (is(real_t == real))
version(MSVC_X87) static if (is(real_t == real))
pure @trusted
static bool isSNaN(longdouble_soft ld)
{
Expand Down Expand Up @@ -239,7 +243,7 @@ extern (C++) struct CTFloat
@system
static int sprint(char* str, size_t size, char fmt, real_t x)
{
version(CRuntime_Microsoft)
version(MSVC_X87)
{
auto len = cast(int) ld_sprint(str, size, fmt, longdouble_soft(x));
}
Expand Down
5 changes: 4 additions & 1 deletion dmd/root/longdouble.d
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module dmd.root.longdouble;

version (CRuntime_Microsoft)
{
static if (real.sizeof > 8)
version (AArch64)
alias longdouble = real; // 64-bit
else static if (real.sizeof > 8)
alias longdouble = real;
else
alias longdouble = longdouble_soft;
Expand All @@ -24,6 +26,7 @@ else
// longdouble_soft needed when building the backend with
// Visual C or the frontend with LDC on Windows
version (CRuntime_Microsoft):
version (AArch64) { /* cannot use x87 inline asm on arm64 host */ } else:
extern (C++):
nothrow:
@nogc:
Expand Down
6 changes: 3 additions & 3 deletions dmd/root/longdouble.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#pragma once

#if !_MSC_VER // has native 10 byte doubles
#if !defined(_MSC_VER) || defined(_M_ARM64)
#include <stdio.h>
typedef long double longdouble;
typedef volatile long double volatile_longdouble;
Expand Down Expand Up @@ -48,7 +48,7 @@ inline size_t ld_sprint(char* str, size_t size, int fmt, longdouble x)
#undef snprintf
#endif

#else
#else // defined(_MSC_VER) && !defined(_M_ARM64)

#include <float.h>
#include <limits>
Expand Down Expand Up @@ -264,4 +264,4 @@ typedef longdouble_soft longdouble;
// is not required.
typedef longdouble_soft volatile_longdouble;

#endif // !_MSC_VER
#endif // defined(_MSC_VER) && !defined(_M_ARM64)
4 changes: 2 additions & 2 deletions gen/ctfloat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ void CTFloat::initialize() {
if (apSemantics)
return;

#ifdef _MSC_VER
// MSVC hosts use dmd.root.longdouble (80-bit x87)
#if defined(_MSC_VER) && !defined(_M_ARM64)
// MSVC x86[_64] hosts use dmd.root.longdouble (80-bit x87)
apSemantics = &APFloat::x87DoubleExtended();
#else
static_assert(std::numeric_limits<real_t>::is_specialized,
Expand Down
Loading