Add CMake toolchains and update CI

This commit is contained in:
2025-11-09 14:50:45 -07:00
parent d85671e3c6
commit 4a7a6b9d72
18 changed files with 453 additions and 81 deletions

View File

@@ -13,36 +13,62 @@ env:
jobs:
build:
name: Build (${{ matrix.display }})
name: Build ${{ matrix.display }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- id: ubuntu-debug
display: Debug
display: Debug (32-bit)
dockerfile: Dockerfile.ubuntu
build_type: Debug
build_type: debug
default: false
suffix: -ubuntu-debug
- id: ubuntu-release
display: Release
display: Release (32-bit)
dockerfile: Dockerfile.ubuntu
build_type: Release
build_type: release
default: false
suffix: -ubuntu
- id: ubuntu-debug64
display: Debug (64-bit)
dockerfile: Dockerfile.ubuntu
build_type: debug64
default: false
suffix: 64-ubuntu-debug
- id: ubuntu-release64
display: Release (64-bit)
dockerfile: Dockerfile.ubuntu
build_type: release64
default: false
suffix: 64-ubuntu
- id: static-debug
display: Static, Debug
display: Debug (Static, 32-bit)
dockerfile: Dockerfile
build_type: Debug
build_type: debug
platform: linux/386
default: false
suffix: -alpine-debug
- id: static-release
display: Static, Release
display: Release (Static, 32-bit)
dockerfile: Dockerfile
build_type: Release
build_type: release
platform: linux/386
default: true
suffix: -alpine
- id: static-debug64
display: Debug (Static, 64-bit)
dockerfile: Dockerfile
build_type: debug
default: false
suffix: 64-alpine-debug
- id: static-release64
display: Release (Static, 64-bit)
dockerfile: Dockerfile
build_type: release
default: false
suffix: 64-alpine
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -79,6 +105,7 @@ jobs:
BUILD_TYPE=${{ matrix.build_type }}
WIBO_VERSION=${{ steps.version.outputs.wibo_version }}
target: build
platforms: ${{ matrix.platform || 'linux/amd64' }}
- name: Tests
run: >

View File

@@ -4,11 +4,6 @@ project(wibo LANGUAGES ASM C CXX)
set(CMAKE_CXX_STANDARD 20)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE)
endif()
set(WIBO_VERSION "" CACHE STRING "Version string for the wibo binary; if empty, attempts to use git describe")
if(NOT "${WIBO_VERSION}" STREQUAL "")
@@ -35,11 +30,6 @@ if(NOT DEFINED WIBO_VERSION_STRING OR "${WIBO_VERSION_STRING}" STREQUAL "")
set(WIBO_VERSION_STRING "unknown")
endif()
# Clang on Linux needs help finding the 32-bit headers
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
include_directories(/usr/i686-linux-gnu/include)
endif()
set(WIBO_GENERATED_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${WIBO_GENERATED_HEADER_DIR})
configure_file(
@@ -48,20 +38,27 @@ configure_file(
@ONLY
)
option(WIBO_64 "Build wibo for 64-bit host" OFF)
# Detect if we're building for 64-bit based on the target architecture
# CMAKE_SIZEOF_VOID_P is set by the project() command and the toolchain
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(WIBO_64 ON)
message(STATUS "Detected 64-bit target architecture")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(WIBO_64 OFF)
message(STATUS "Detected 32-bit target architecture")
else()
message(FATAL_ERROR "Unknown pointer size: ${CMAKE_SIZEOF_VOID_P}")
endif()
option(WIBO_ENABLE_FIXTURE_TESTS "Enable Win32 fixture tests (requires i686-w64-mingw32)" ON)
option(WIBO_ENABLE_LIBURING "Enable liburing for asynchronous I/O" OFF)
set(WIBO_ENABLE_LTO "AUTO" CACHE STRING "Enable link-time optimization (LTO)")
set_property(CACHE WIBO_ENABLE_LTO PROPERTY STRINGS "AUTO" "ON" "OFF")
add_compile_options(
$<IF:$<BOOL:${WIBO_64}>,-m64,-m32>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)
add_link_options(
$<IF:$<BOOL:${WIBO_64}>,-m64,-m32>
)
if (WIBO_ENABLE_LTO STREQUAL "AUTO")
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
@@ -324,7 +321,6 @@ function(wibo_codegen_module)
${module_HEADERS}
)
target_sources(wibo PRIVATE ${out_asm})
set_source_files_properties(${out_asm} PROPERTIES COMPILE_FLAGS $<IF:$<BOOL:${WIBO_64}>,-m64,-m32>)
endfunction()
wibo_codegen_module(NAME advapi32 HEADERS

View File

@@ -1,5 +1,5 @@
{
"version": 2,
"version": 3,
"configurePresets": [
{
"name": "ninja-base",
@@ -21,19 +21,65 @@
{
"name": "debug",
"displayName": "Debug",
"description": "Debug build (32-bit Linux)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/i686-linux-gcc.cmake"
}
},
{
"name": "debug-macos",
"displayName": "Debug",
"description": "Debug build (64-bit macOS)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-darwin.cmake"
}
},
{
"name": "release",
"displayName": "Release",
"description": "Release build (32-bit Linux)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/i686-linux-gcc.cmake"
}
},
{
"name": "release-macos",
"displayName": "Release",
"description": "Release build (64-bit macOS)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-darwin.cmake"
}
},
{
@@ -41,8 +87,14 @@
"displayName": "Debug (Clang)",
"inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/debug-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/i686-linux-clang.cmake"
}
},
{
@@ -50,8 +102,14 @@
"displayName": "Release (Clang)",
"inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/release-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/i686-linux-clang.cmake"
}
},
{
@@ -59,9 +117,14 @@
"displayName": "Debug (64-bit)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/debug64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"WIBO_64": "ON"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-linux-gcc.cmake"
}
},
{
@@ -69,9 +132,14 @@
"displayName": "Release (64-bit)",
"inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/release64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"WIBO_64": "ON"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-linux-gcc.cmake"
}
},
{
@@ -79,9 +147,14 @@
"displayName": "Debug (64-bit, Clang)",
"inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/debug64-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"WIBO_64": "ON"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-linux-clang.cmake"
}
},
{
@@ -89,9 +162,14 @@
"displayName": "Release (64-bit, Clang)",
"inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/release64-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"WIBO_64": "ON"
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/x86_64-linux-clang.cmake"
}
}
],
@@ -103,6 +181,13 @@
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Debug"
},
{
"name": "debug-macos",
"displayName": "Build (Debug)",
"configurePreset": "debug-macos",
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Debug"
},
{
"name": "release",
"displayName": "Build (Release)",
@@ -110,6 +195,13 @@
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Release"
},
{
"name": "release-macos",
"displayName": "Build (Release)",
"configurePreset": "release-macos",
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Release"
},
{
"name": "debug-clang",
"displayName": "Build (Debug, Clang)",
@@ -164,6 +256,16 @@
"shortProgress": true
}
},
{
"name": "debug-macos",
"displayName": "Run tests (Debug)",
"configurePreset": "debug-macos",
"configuration": "Debug",
"output": {
"outputOnFailure": true,
"shortProgress": true
}
},
{
"name": "release",
"displayName": "Run tests (Release)",
@@ -174,6 +276,16 @@
"shortProgress": true
}
},
{
"name": "release-macos",
"displayName": "Run tests (Release)",
"configurePreset": "release-macos",
"configuration": "Release",
"output": {
"outputOnFailure": true,
"shortProgress": true
}
},
{
"name": "debug-clang",
"displayName": "Run tests (Debug, Clang)",

View File

@@ -1,5 +1,5 @@
# Build stage
FROM --platform=linux/i386 alpine:latest AS build
FROM alpine:latest AS build
# Install dependencies
RUN apk add --no-cache \
@@ -11,6 +11,7 @@ RUN apk add --no-cache \
coreutils \
git \
linux-headers \
lld \
llvm-dev \
make \
mingw-w64-binutils \
@@ -22,8 +23,11 @@ RUN apk add --no-cache \
WORKDIR /wibo
COPY . /wibo
# Build type (Release, Debug, RelWithDebInfo, MinSizeRel)
ARG BUILD_TYPE=Release
# Target platform (automatically set by Docker buildx)
ARG TARGETPLATFORM
# Build type (release, debug)
ARG BUILD_TYPE=release
# Enable link-time optimization (LTO) (AUTO, ON, OFF)
ARG ENABLE_LTO=AUTO
@@ -32,24 +36,32 @@ ARG ENABLE_LTO=AUTO
ARG WIBO_VERSION
# Build static binary
RUN cmake -S /wibo -B /wibo/build -G Ninja \
-DCMAKE_BUILD_TYPE:STRING="$BUILD_TYPE" \
-DCMAKE_C_COMPILER:STRING=clang \
-DCMAKE_CXX_COMPILER:STRING=clang++ \
-DCMAKE_C_FLAGS:STRING="-static" \
-DCMAKE_CXX_FLAGS:STRING="-static" \
-DMI_LIBC_MUSL:BOOL=ON \
-DWIBO_ENABLE_LIBURING:BOOL=ON \
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
PRESET="${BUILD_TYPE}64-clang"; \
TOOLCHAIN="/wibo/cmake/toolchains/x86_64-alpine-linux-musl.cmake"; \
elif [ "$TARGETPLATFORM" = "linux/386" ]; then \
PRESET="${BUILD_TYPE}-clang"; \
TOOLCHAIN="/wibo/cmake/toolchains/i586-alpine-linux-musl.cmake"; \
else \
echo "Error: Unsupported platform '$TARGETPLATFORM'. Supported platforms: linux/amd64, linux/386" >&2; \
exit 1; \
fi; \
echo "Building for $TARGETPLATFORM with preset $PRESET" \
&& cmake -S /wibo --preset "$PRESET" \
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
-DWIBO_ENABLE_LTO:STRING="$ENABLE_LTO" \
-DWIBO_VERSION:STRING="$WIBO_VERSION" \
&& cmake --build /wibo/build --verbose \
&& ( [ "$BUILD_TYPE" != "Release" ] || strip -g /wibo/build/wibo )
&& cmake --build --preset "$PRESET" --verbose \
&& ( [ "$BUILD_TYPE" != "release"* ] || strip -g "/wibo/build/$PRESET/wibo" ) \
&& cp "/wibo/build/$PRESET/wibo" /usr/local/bin/wibo
# Export binary (usage: docker build --target export --output build .)
FROM scratch AS export
COPY --from=build /wibo/build/wibo .
COPY --from=build /usr/local/bin/wibo .
# Runnable container
FROM alpine:latest
COPY --from=build /wibo/build/wibo /usr/local/sbin/wibo
CMD /usr/local/sbin/wibo
COPY --from=build /usr/local/bin/wibo /usr/local/bin/wibo
CMD ["/usr/local/bin/wibo"]

View File

@@ -34,8 +34,8 @@ RUN apt-get update \
WORKDIR /wibo
COPY . /wibo
# Build type (Release, Debug, RelWithDebInfo, MinSizeRel)
ARG BUILD_TYPE=Release
# Build type (release, debug, release64, debug64)
ARG BUILD_TYPE=release
# Enable link-time optimization (LTO) (AUTO, ON, OFF)
ARG ENABLE_LTO=AUTO
@@ -43,22 +43,22 @@ ARG ENABLE_LTO=AUTO
# Version string (if not provided, defaults to "unknown")
ARG WIBO_VERSION
RUN cmake -S /wibo -B /wibo/build -G Ninja \
# Build dynamic binary
RUN PRESET=${BUILD_TYPE}-clang; \
cmake -S /wibo --preset "$PRESET" \
-DCMAKE_AR:PATH=/usr/bin/llvm-ar \
-DCMAKE_RANLIB:PATH=/usr/bin/llvm-ranlib \
-DCMAKE_BUILD_TYPE:STRING="$BUILD_TYPE" \
-DCMAKE_EXE_LINKER_FLAGS:STRING="-m32 -fuse-ld=lld" \
-DWIBO_ENABLE_LIBURING:BOOL=ON \
-DWIBO_ENABLE_LTO:STRING="$ENABLE_LTO" \
-DWIBO_VERSION:STRING="$WIBO_VERSION" \
&& LIBCLANG_PATH=/usr/lib/llvm-18/lib cmake --build /wibo/build --verbose \
&& ( [ "$BUILD_TYPE" != "Release" ] || strip -g /wibo/build/wibo )
&& LIBCLANG_PATH=/usr/lib/llvm-18/lib cmake --build --preset "$PRESET" --verbose \
&& ( [ "$BUILD_TYPE" != "release"* ] || strip -g "/wibo/build/$PRESET/wibo" ) \
&& cp "/wibo/build/$PRESET/wibo" /usr/local/bin/wibo
# Export binary (usage: docker build -f Dockerfile.ubuntu --target export --output dist .)
FROM scratch AS export
COPY --from=build /wibo/build/wibo .
COPY --from=build /usr/local/bin/wibo .
# Runnable container
FROM ubuntu:24.04
COPY --from=build /wibo/build/wibo /usr/local/sbin/wibo
CMD ["/usr/local/sbin/wibo"]
COPY --from=build /usr/local/bin/wibo /usr/local/bin/wibo
CMD ["/usr/local/bin/wibo"]

View File

@@ -0,0 +1,33 @@
# Toolchain file for static 32-bit Linux builds with Clang and musl
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)
# Specify the compiler
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_LINKER_TYPE LLD)
# Set the target triple for cross-compilation
set(TARGET i586-alpine-linux-musl)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 32-bit compilation
set(CMAKE_C_FLAGS_INIT "-static")
set(CMAKE_CXX_FLAGS_INIT "-static")
set(CMAKE_ASM_FLAGS_INIT "-static")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Inform mimalloc that we are using musl libc
set(MI_LIBC_MUSL ON)

View File

@@ -0,0 +1,36 @@
# Toolchain file for 32-bit Linux builds with Clang
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)
# Specify the compiler
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_LINKER_TYPE LLD)
# Set the target triple for cross-compilation
set(TARGET i686-linux-gnu)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 32-bit compilation
set(CMAKE_C_FLAGS_INIT "-m32")
set(CMAKE_CXX_FLAGS_INIT "-m32")
set(CMAKE_ASM_FLAGS_INIT "-m32")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-m32 -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-m32 -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-m32 -fuse-ld=lld")
# Set library architecture
set(CMAKE_LIBRARY_ARCHITECTURE i386-linux-gnu)
# Clang on Linux needs help finding the 32-bit headers
include_directories(SYSTEM /usr/i686-linux-gnu/include)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -0,0 +1,32 @@
# Toolchain file for 32-bit Linux builds with GCC
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)
# Specify the compiler
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_ASM_COMPILER gcc)
# Set the target triple for cross-compilation
set(TARGET i686-linux-gnu)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 32-bit compilation
set(CMAKE_C_FLAGS_INIT "-m32")
set(CMAKE_CXX_FLAGS_INIT "-m32")
set(CMAKE_ASM_FLAGS_INIT "-m32")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-m32")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-m32")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-m32")
# Set library architecture
set(CMAKE_LIBRARY_ARCHITECTURE i386-linux-gnu)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -0,0 +1,29 @@
# Toolchain file for static 64-bit Linux builds with Clang and musl
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# Specify the compiler
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_ASM_COMPILER clang)
# Set the target triple for cross-compilation
set(TARGET x86_64-alpine-linux-musl)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 64-bit compilation
set(CMAKE_C_FLAGS_INIT "-static")
set(CMAKE_CXX_FLAGS_INIT "-static")
set(CMAKE_ASM_FLAGS_INIT "-static")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=lld -static")
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -0,0 +1,20 @@
# Toolchain file for x86_64 macOS builds
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# Set the target triple for cross-compilation
set(TARGET x86_64-apple-darwin)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force x86_64 architecture
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architecture for macOS" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum macOS deployment version" FORCE)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -0,0 +1,33 @@
# Toolchain file for 64-bit Linux builds with Clang
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# Specify the compiler
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_LINKER_TYPE LLD)
# Set the target triple for cross-compilation
set(TARGET x86_64-linux-gnu)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 64-bit compilation
set(CMAKE_C_FLAGS_INIT "-m64")
set(CMAKE_CXX_FLAGS_INIT "-m64")
set(CMAKE_ASM_FLAGS_INIT "-m64")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-m64 -fuse-ld=lld")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-m64 -fuse-ld=lld")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-m64 -fuse-ld=lld")
# Set library architecture
set(CMAKE_LIBRARY_ARCHITECTURE x86_64-linux-gnu)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -0,0 +1,32 @@
# Toolchain file for 64-bit Linux builds with GCC
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
# Specify the compiler
set(CMAKE_C_COMPILER gcc)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_ASM_COMPILER gcc)
# Set the target triple for cross-compilation
set(TARGET x86_64-linux-gnu)
set(CMAKE_C_COMPILER_TARGET ${TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${TARGET})
set(CMAKE_ASM_COMPILER_TARGET ${TARGET})
# Force 64-bit compilation
set(CMAKE_C_FLAGS_INIT "-m64")
set(CMAKE_CXX_FLAGS_INIT "-m64")
set(CMAKE_ASM_FLAGS_INIT "-m64")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-m64")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-m64")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-m64")
# Set library architecture
set(CMAKE_LIBRARY_ARCHITECTURE x86_64-linux-gnu)
# Search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

View File

@@ -101,8 +101,8 @@ LONGLONG timespecToFileTime(const timespec &ts) {
if (ticks < 0.0L) {
return 0;
}
if (ticks > static_cast<long double>(std::numeric_limits<LONGLONG>::max())) {
return std::numeric_limits<LONGLONG>::max();
if (ticks > static_cast<long double>(std::numeric_limits<long long>::max())) {
return std::numeric_limits<long long>::max();
}
return static_cast<LONGLONG>(ticks);
#endif

View File

@@ -1,26 +1,26 @@
#include "macros.h"
#ifdef __clang__
#define ASM_TYPE(NAME, TYPE)
#define ASM_END(NAME)
#else
#if GNU_ASSEMBLER
#define ASM_TYPE(NAME, TYPE) .type NAME, TYPE
#define ASM_END(NAME) .size NAME, .- NAME
#else
#define ASM_TYPE(NAME, TYPE)
#define ASM_END(NAME)
#endif
#define ASM_GLOBAL(NAME, TYPE) \
.globl SYMBOL_NAME(NAME); \
ASM_TYPE(SYMBOL_NAME(NAME), TYPE); \
SYMBOL_NAME(NAME) :
#ifdef __clang__
#if GNU_ASSEMBLER
#define ASM_WEAK(NAME, TYPE) \
.globl SYMBOL_NAME(NAME); \
.weak_definition SYMBOL_NAME(NAME); \
ASM_TYPE(SYMBOL_NAME(NAME), TYPE) \
.weak SYMBOL_NAME(NAME); \
ASM_TYPE(SYMBOL_NAME(NAME), TYPE); \
SYMBOL_NAME(NAME) :
#else
#define ASM_WEAK(NAME, TYPE) \
.weak SYMBOL_NAME(NAME); \
.globl SYMBOL_NAME(NAME); \
.weak_definition SYMBOL_NAME(NAME); \
ASM_TYPE(SYMBOL_NAME(NAME), TYPE) \
SYMBOL_NAME(NAME) :
#endif

View File

@@ -26,6 +26,16 @@
#error "Unsupported platform"
#endif
#endif
#if defined(__linux__)
#define GNU_ASSEMBLER 1
#elif defined(__clang__)
#define GNU_ASSEMBLER 0
#else
#error "Unsupported platform"
#endif
#ifndef __USER_LABEL_PREFIX__
#define __USER_LABEL_PREFIX__
#endif
@@ -46,7 +56,7 @@
#define ASM_SIZE_TYPE "long"
#endif
#if __ELF__
#define ASM_RODATA_SECTION ".rodata"
#define ASM_RODATA_SECTION ".section .rodata"
#else
#define ASM_RODATA_SECTION ".section __TEXT, __const"
#endif
@@ -68,6 +78,4 @@
static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(&GLUE(symbol, End)) - \
reinterpret_cast<std::uintptr_t>(&symbol))
#define INCLUDE_BIN_SPAN(symbol) std::span<const std::uint8_t>(symbol, INCLUDE_BIN_SIZE(symbol))
#endif
#endif
#endif

View File

@@ -54,9 +54,11 @@ ASM_END(tebThreadSetup)
.macro stubThunkX number
#if defined(__x86_64__)
ASM_GLOBAL(_Z9stubThunkILm\()\number\()EEvv, @function)
#define STUB_THUNK_SYMBOL _Z9stubThunkILm\()\number\()EEvv
ASM_GLOBAL(STUB_THUNK_SYMBOL, @function)
#else
ASM_GLOBAL(_Z9stubThunkILj\()\number\()EEvv, @function)
#define STUB_THUNK_SYMBOL _Z9stubThunkILj\()\number\()EEvv
ASM_GLOBAL(STUB_THUNK_SYMBOL, @function)
#endif
pop eax
push \number

View File

@@ -89,7 +89,7 @@ static void test_rtl_time_to_seconds_invalid_inputs(void) {
TEST_CHECK_EQ(FALSE, gFns.time_to_seconds(&before_epoch, &seconds));
LARGE_INTEGER beyond_range = {
.QuadPart = (LONGLONG)(kUnixEpochAsFileTime + (0x1'00000000ULL * kHundredNsPerSecond))};
.QuadPart = (LONGLONG)(kUnixEpochAsFileTime + (0x100000000ULL * kHundredNsPerSecond))};
TEST_CHECK_EQ(FALSE, gFns.time_to_seconds(&beyond_range, &seconds));
}

View File

@@ -1079,13 +1079,13 @@ def main() -> int:
if args.arch == "x86":
arch = Arch.X86
target = "i686-pc-linux-gnu"
target = "i686-linux-gnu"
elif args.arch == "x86_64":
arch = Arch.X86_64
if sys.platform == "darwin":
target = "x86_64-apple-darwin"
else:
target = "x86_64-pc-linux-gnu"
target = "x86_64-linux-gnu"
else:
raise ValueError(f"Unsupported architecture: {args.arch}")