Skip to content

Commit 3e8f51a

Browse files
GulinSSTerrorJack
authored andcommitted
Add support for Windows Aarch64
Co-authored-by: Cheng Shao <[email protected]>
1 parent dcdbeb0 commit 3e8f51a

File tree

7 files changed

+27
-6
lines changed

7 files changed

+27
-6
lines changed

Cabal/src/Distribution/Compat/Environment.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ setEnv_ key value = withCWString key $ \k -> withCWString value $ \v -> do
6363
{- FOURMOLU_DISABLE -}
6464
# if defined(i386_HOST_ARCH)
6565
# define WINDOWS_CCONV stdcall
66-
# elif defined(x86_64_HOST_ARCH)
66+
# elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH)
6767
# define WINDOWS_CCONV ccall
6868
# else
6969
# error Unknown mingw32 arch

Cabal/src/Distribution/Simple/Build/PathsModule.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ generatePathsModule pkg_descr lbi clbi =
5151
, Z.zIsWindows = isWindows
5252
, Z.zIsI386 = buildArch == I386
5353
, Z.zIsX8664 = buildArch == X86_64
54+
, Z.zIsAarch64 = buildArch == AArch64
5455
, Z.zNot = not
5556
, Z.zManglePkgName = showPkgName
5657
, Z.zPrefix = show flat_prefix

Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data Z
1212
zIsWindows :: Bool,
1313
zIsI386 :: Bool,
1414
zIsX8664 :: Bool,
15+
zIsAarch64 :: Bool,
1516
zPrefix :: FilePath,
1617
zBindir :: FilePath,
1718
zLibdir :: FilePath,
@@ -284,9 +285,16 @@ render z_root = execWriter $ do
284285
tell " c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32\n"
285286
return ()
286287
else do
287-
tell "-- win32 supported only with I386, X86_64\n"
288-
tell "c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32\n"
289-
tell "c_GetModuleFileName = _\n"
288+
if (zIsAarch64 z_root)
289+
then do
290+
tell "foreign import ccall unsafe \"windows.h GetModuleFileNameW\"\n"
291+
tell " c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32\n"
292+
return ()
293+
else do
294+
tell "-- win32 supported only with I386, X86_64, Aarch64\n"
295+
tell "c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32\n"
296+
tell "c_GetModuleFileName = _\n"
297+
return ()
290298
return ()
291299
return ()
292300
tell "\n"

cabal-dev-scripts/src/GenPathsModule.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ $(capture "decls" [d|
3232
, zIsWindows :: Bool
3333
, zIsI386 :: Bool
3434
, zIsX8664 :: Bool
35+
, zIsAarch64 :: Bool
3536

3637
, zPrefix :: FilePath
3738
, zBindir :: FilePath

cabal-install/src/Distribution/Client/Compat/ExecutablePath.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ getExecutablePath = readSymbolicLink $ "/proc/self/exe"
123123

124124
# if defined(i386_HOST_ARCH)
125125
# define WINDOWS_CCONV stdcall
126-
# elif defined(x86_64_HOST_ARCH)
126+
# elif defined(x86_64_HOST_ARCH) || defined(aarch64_HOST_ARCH)
127127
# define WINDOWS_CCONV ccall
128128
# else
129129
# error Unknown mingw32 arch

changelog.d/pr-10705

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
synopsis: 'Add support for Windows Aarch64'
3+
packages: [Cabal, cabal-install]
4+
prs: 10705
5+
---
6+
7+
Adds to preprocessor branches the option to support `aarch64_HOST_ARCH` platform on Windows Aarch64 target.
8+
`ccall` convention is used at Aarch64, same as for `x86_64_HOST_ARCH`. Introduce `zIsAarch64` to make paths generation support Windows Aarch64 target.

templates/Paths_pkg.template.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,13 @@ getPrefixDirRel dirRel = try_size 2048 -- plenty, PATH_MAX is 512 under Win32.
152152
foreign import stdcall unsafe "windows.h GetModuleFileNameW"
153153
c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32
154154
{% elif isX8664 %}
155+
foreign import ccall unsafe "windows.h GetModuleFileNameW"
156+
c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32
157+
{% elif isAarch64 %}
155158
foreign import ccall unsafe "windows.h GetModuleFileNameW"
156159
c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32
157160
{% else %}
158-
-- win32 supported only with I386, X86_64
161+
-- win32 supported only with I386, X86_64, Aarch64
159162
c_GetModuleFileName :: Ptr () -> CWString -> Int32 -> IO Int32
160163
c_GetModuleFileName = _
161164
{% endif %}

0 commit comments

Comments
 (0)