Skip to content

Commit

Permalink
Windows: Support building with strict compatibility
Browse files Browse the repository at this point in the history
This commit adds the `STRICT_APPLE_COMPATIBILITY` CMake option which will force `BOOL` to defined as an `signed char` on Windows instead of an `int`, as having different types for `BOOL` on different platforms creates serialization issues.

On MSYS, the `BOOL` type is defined in` minwindef` like this:

```
  typedef int BOOL;
```

To prevent this header from defining a conflicting `BOOL` type, this commit also defines `__OBJC_BOOL`.
  • Loading branch information
qmfrederik committed Nov 14, 2024
1 parent a9d0313 commit 2466c57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ jobs:
os: [ windows-2019 ]
msystem: [ ucrt64, mingw64, clang64 ]
build-type: [ Release, Debug ]
strict-apple-compatibility: [ ON, OFF ]
include:
- msystem: ucrt64
package-prefix: ucrt-x86_64
Expand All @@ -226,7 +227,7 @@ jobs:
# Don't abort runners if a single one fails
fail-fast: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} ${{ matrix.msystem }} ${{ matrix.build-type}}
name: ${{ matrix.os }} ${{ matrix.msystem }} ${{ matrix.build-type}} (Strict Apple compatibility ${{ matrix.strict-apple-compatibility }})
defaults:
run:
shell: msys2 {0}
Expand All @@ -241,7 +242,7 @@ jobs:
run: |
mkdir build
cd build
${{ matrix.cmake-flags }} cmake .. -DTESTS=ON -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }}
${{ matrix.cmake-flags }} cmake .. -DTESTS=ON -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DSTRICT_APPLE_COMPATIBILITY=${{ matrix.strict-apple-compatibility }}
- name: Build
working-directory: build
run: |
Expand All @@ -256,7 +257,7 @@ jobs:
cmake --install . --prefix=../dist
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.msystem }}-${{ matrix.build-type }}
name: ${{ matrix.msystem }}-${{ matrix.build-type }}-compat-${{ matrix.strict-apple-compatibility }}
path: dist/

android:
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ endif()
message(STATUS "Architecture as detected by CMake: ${CMAKE_SYSTEM_PROCESSOR}")

# Build configuration
add_compile_definitions(GNUSTEP __OBJC_RUNTIME_INTERNAL__=1)
add_compile_definitions(GNUSTEP __OBJC_RUNTIME_INTERNAL__=1 __OBJC_BOOL)

set(CMAKE_CXX_STANDARD 17)

Expand Down Expand Up @@ -140,13 +140,15 @@ option(DEBUG_ARC_COMPAT
option(ENABLE_OBJCXX "Enable support for Objective-C++" ON)
option(TESTS "Enable building the tests")
option(EMBEDDED_BLOCKS_RUNTIME "Include an embedded blocks runtime, rather than relying on libBlocksRuntime to supply it" ON)
option(STRICT_APPLE_COMPATIBILITY "Use strict Apple compatibility, always defining BOOL as signed char" OFF)

# For release builds, we disable spamming the terminal with warnings about
# selector type mismatches
add_compile_definitions($<$<CONFIG:Release>:NO_SELECTOR_MISMATCH_WARNINGS>)
add_compile_definitions($<$<BOOL:${TYPE_DEPENDENT_DISPATCH}>:TYPE_DEPENDENT_DISPATCH>)
add_compile_definitions($<$<BOOL:${ENABLE_TRACING}>:WITH_TRACING=1>)
add_compile_definitions($<$<BOOL:${DEBUG_ARC_COMPAT}>:DEBUG_ARC_COMPAT>)
add_compile_definitions($<$<BOOL:${STRICT_APPLE_COMPATIBILITY}>:STRICT_APPLE_COMPATIBILITY>)

if (OLDABI_COMPAT)
list(APPEND libobjc_C_SRCS legacy.c abi_version.c statics_loader.c)
Expand Down

0 comments on commit 2466c57

Please sign in to comment.