Skip to content

Commit a82d3bc

Browse files
committed
Improve cross-compilation
1 parent 4447f3d commit a82d3bc

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

bindings/c/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ These are the bindings to use AccessKit from other languages through FFI such as
44

55
## How to use in a CMake project
66

7-
Decompress an accesskit_c release and place the resulting folder somewhere:
7+
Decompress an accesskit_c release and place the resulting folder somewhere either:
88

99
- already known by CMake,
1010
- listed in your `CMAKE_PREFIX_PATH`,
@@ -46,3 +46,17 @@ Once inside the `bindings/c` directory, CMake can be used like this to build the
4646
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
4747
cmake --build build
4848
```
49+
50+
### Notes on cross-compiling
51+
52+
On Windows, you will need to pass the `-A` flag when configuring the project. For instance, to target ARM64:
53+
54+
```
55+
cmake -S . -B build -A ARM64
56+
```
57+
58+
On other platforms you will have to specify which Rust target to use, as well as tell CMake for which architecture to compile. Here is how you would cross-compile for Linux X86 from Linux AMD64:
59+
60+
```
61+
cmake -S . -B build -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=x86 -DRust_CARGO_TARGET=i686-unknown-linux-gnu
62+
```

bindings/c/accesskit-config.cmake

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ elseif (WIN32)
1212
endif()
1313
if (CMAKE_VS_PLATFORM_NAME)
1414
string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" LOWER_VS_PLATFORM_NAME)
15-
if ("${LOWER_VS_PLATFORM_NAME}" STREQUAL "arm64")
15+
if ("${LOWER_VS_PLATFORM_NAME}" STREQUAL "win32")
16+
set(_ACCESSKIT_ARCH x86)
17+
elseif("${LOWER_VS_PLATFORM_NAME}" STREQUAL "x64")
18+
set(_ACCESSKIT_ARCH x86_64)
19+
elseif ("${LOWER_VS_PLATFORM_NAME}" STREQUAL "arm64")
1620
set(_ACCESSKIT_ARCH "arm64")
1721
endif()
1822
endif()
@@ -21,12 +25,12 @@ if (NOT _ACCESSKIT_TOOLCHAIN)
2125
set(_ACCESSKIT_TOOLCHAIN "")
2226
endif()
2327
if (NOT _ACCESSKIT_ARCH)
24-
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64)$")
25-
set(_ACCESSKIT_ARCH "x86_64")
28+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|amd64|x86_64)$")
29+
set(_ACCESSKIT_ARCH x86_64)
2630
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM64|arm64|aarch64)$")
27-
set(_ACCESSKIT_ARCH "arm64")
31+
set(_ACCESSKIT_ARCH arm64)
2832
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^(X86|x86|i686)$")
29-
set(_ACCESSKIT_ARCH "x86")
33+
set(_ACCESSKIT_ARCH x86)
3034
endif()
3135
endif()
3236
set(ACCESSKIT_LIBRARIES_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/${_ACCESSKIT_OS}/${_ACCESSKIT_ARCH}/${_ACCESSKIT_TOOLCHAIN}")

0 commit comments

Comments
 (0)