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

View File

@@ -4,11 +4,6 @@ project(wibo LANGUAGES ASM C CXX)
set(CMAKE_CXX_STANDARD 20) 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") set(WIBO_VERSION "" CACHE STRING "Version string for the wibo binary; if empty, attempts to use git describe")
if(NOT "${WIBO_VERSION}" STREQUAL "") 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") set(WIBO_VERSION_STRING "unknown")
endif() 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) set(WIBO_GENERATED_HEADER_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
file(MAKE_DIRECTORY ${WIBO_GENERATED_HEADER_DIR}) file(MAKE_DIRECTORY ${WIBO_GENERATED_HEADER_DIR})
configure_file( configure_file(
@@ -48,20 +38,27 @@ configure_file(
@ONLY @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_FIXTURE_TESTS "Enable Win32 fixture tests (requires i686-w64-mingw32)" ON)
option(WIBO_ENABLE_LIBURING "Enable liburing for asynchronous I/O" OFF) option(WIBO_ENABLE_LIBURING "Enable liburing for asynchronous I/O" OFF)
set(WIBO_ENABLE_LTO "AUTO" CACHE STRING "Enable link-time optimization (LTO)") set(WIBO_ENABLE_LTO "AUTO" CACHE STRING "Enable link-time optimization (LTO)")
set_property(CACHE WIBO_ENABLE_LTO PROPERTY STRINGS "AUTO" "ON" "OFF") set_property(CACHE WIBO_ENABLE_LTO PROPERTY STRINGS "AUTO" "ON" "OFF")
add_compile_options( add_compile_options(
$<IF:$<BOOL:${WIBO_64}>,-m64,-m32>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions> $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti> $<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
) )
add_link_options(
$<IF:$<BOOL:${WIBO_64}>,-m64,-m32>
)
if (WIBO_ENABLE_LTO STREQUAL "AUTO") if (WIBO_ENABLE_LTO STREQUAL "AUTO")
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel") if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
@@ -324,7 +321,6 @@ function(wibo_codegen_module)
${module_HEADERS} ${module_HEADERS}
) )
target_sources(wibo PRIVATE ${out_asm}) target_sources(wibo PRIVATE ${out_asm})
set_source_files_properties(${out_asm} PROPERTIES COMPILE_FLAGS $<IF:$<BOOL:${WIBO_64}>,-m64,-m32>)
endfunction() endfunction()
wibo_codegen_module(NAME advapi32 HEADERS wibo_codegen_module(NAME advapi32 HEADERS

View File

@@ -1,5 +1,5 @@
{ {
"version": 2, "version": 3,
"configurePresets": [ "configurePresets": [
{ {
"name": "ninja-base", "name": "ninja-base",
@@ -21,19 +21,65 @@
{ {
"name": "debug", "name": "debug",
"displayName": "Debug", "displayName": "Debug",
"description": "Debug build (32-bit Linux)",
"inherits": ["ninja-base"], "inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/debug", "binaryDir": "${sourceDir}/build/debug",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "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", "name": "release",
"displayName": "Release", "displayName": "Release",
"description": "Release build (32-bit Linux)",
"inherits": ["ninja-base"], "inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/release", "binaryDir": "${sourceDir}/build/release",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "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)", "displayName": "Debug (Clang)",
"inherits": ["ninja-base", "clang-base"], "inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/debug-clang", "binaryDir": "${sourceDir}/build/debug-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "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)", "displayName": "Release (Clang)",
"inherits": ["ninja-base", "clang-base"], "inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/release-clang", "binaryDir": "${sourceDir}/build/release-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "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)", "displayName": "Debug (64-bit)",
"inherits": ["ninja-base"], "inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/debug64", "binaryDir": "${sourceDir}/build/debug64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug", "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)", "displayName": "Release (64-bit)",
"inherits": ["ninja-base"], "inherits": ["ninja-base"],
"binaryDir": "${sourceDir}/build/release64", "binaryDir": "${sourceDir}/build/release64",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Release", "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)", "displayName": "Debug (64-bit, Clang)",
"inherits": ["ninja-base", "clang-base"], "inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/debug64-clang", "binaryDir": "${sourceDir}/build/debug64-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug", "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)", "displayName": "Release (64-bit, Clang)",
"inherits": ["ninja-base", "clang-base"], "inherits": ["ninja-base", "clang-base"],
"binaryDir": "${sourceDir}/build/release64-clang", "binaryDir": "${sourceDir}/build/release64-clang",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": { "cacheVariables": {
"CMAKE_BUILD_TYPE": "Release", "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"], "targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Debug" "configuration": "Debug"
}, },
{
"name": "debug-macos",
"displayName": "Build (Debug)",
"configurePreset": "debug-macos",
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Debug"
},
{ {
"name": "release", "name": "release",
"displayName": "Build (Release)", "displayName": "Build (Release)",
@@ -110,6 +195,13 @@
"targets": ["wibo", "wibo_test_fixtures"], "targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Release" "configuration": "Release"
}, },
{
"name": "release-macos",
"displayName": "Build (Release)",
"configurePreset": "release-macos",
"targets": ["wibo", "wibo_test_fixtures"],
"configuration": "Release"
},
{ {
"name": "debug-clang", "name": "debug-clang",
"displayName": "Build (Debug, Clang)", "displayName": "Build (Debug, Clang)",
@@ -164,6 +256,16 @@
"shortProgress": true "shortProgress": true
} }
}, },
{
"name": "debug-macos",
"displayName": "Run tests (Debug)",
"configurePreset": "debug-macos",
"configuration": "Debug",
"output": {
"outputOnFailure": true,
"shortProgress": true
}
},
{ {
"name": "release", "name": "release",
"displayName": "Run tests (Release)", "displayName": "Run tests (Release)",
@@ -174,6 +276,16 @@
"shortProgress": true "shortProgress": true
} }
}, },
{
"name": "release-macos",
"displayName": "Run tests (Release)",
"configurePreset": "release-macos",
"configuration": "Release",
"output": {
"outputOnFailure": true,
"shortProgress": true
}
},
{ {
"name": "debug-clang", "name": "debug-clang",
"displayName": "Run tests (Debug, Clang)", "displayName": "Run tests (Debug, Clang)",

View File

@@ -1,5 +1,5 @@
# Build stage # Build stage
FROM --platform=linux/i386 alpine:latest AS build FROM alpine:latest AS build
# Install dependencies # Install dependencies
RUN apk add --no-cache \ RUN apk add --no-cache \
@@ -11,6 +11,7 @@ RUN apk add --no-cache \
coreutils \ coreutils \
git \ git \
linux-headers \ linux-headers \
lld \
llvm-dev \ llvm-dev \
make \ make \
mingw-w64-binutils \ mingw-w64-binutils \
@@ -22,8 +23,11 @@ RUN apk add --no-cache \
WORKDIR /wibo WORKDIR /wibo
COPY . /wibo COPY . /wibo
# Build type (Release, Debug, RelWithDebInfo, MinSizeRel) # Target platform (automatically set by Docker buildx)
ARG BUILD_TYPE=Release ARG TARGETPLATFORM
# Build type (release, debug)
ARG BUILD_TYPE=release
# Enable link-time optimization (LTO) (AUTO, ON, OFF) # Enable link-time optimization (LTO) (AUTO, ON, OFF)
ARG ENABLE_LTO=AUTO ARG ENABLE_LTO=AUTO
@@ -32,24 +36,32 @@ ARG ENABLE_LTO=AUTO
ARG WIBO_VERSION ARG WIBO_VERSION
# Build static binary # Build static binary
RUN cmake -S /wibo -B /wibo/build -G Ninja \ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
-DCMAKE_BUILD_TYPE:STRING="$BUILD_TYPE" \ PRESET="${BUILD_TYPE}64-clang"; \
-DCMAKE_C_COMPILER:STRING=clang \ TOOLCHAIN="/wibo/cmake/toolchains/x86_64-alpine-linux-musl.cmake"; \
-DCMAKE_CXX_COMPILER:STRING=clang++ \ elif [ "$TARGETPLATFORM" = "linux/386" ]; then \
-DCMAKE_C_FLAGS:STRING="-static" \ PRESET="${BUILD_TYPE}-clang"; \
-DCMAKE_CXX_FLAGS:STRING="-static" \ TOOLCHAIN="/wibo/cmake/toolchains/i586-alpine-linux-musl.cmake"; \
-DMI_LIBC_MUSL:BOOL=ON \ else \
-DWIBO_ENABLE_LIBURING:BOOL=ON \ 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_ENABLE_LTO:STRING="$ENABLE_LTO" \
-DWIBO_VERSION:STRING="$WIBO_VERSION" \ -DWIBO_VERSION:STRING="$WIBO_VERSION" \
&& cmake --build /wibo/build --verbose \ && cmake --build --preset "$PRESET" --verbose \
&& ( [ "$BUILD_TYPE" != "Release" ] || strip -g /wibo/build/wibo ) && ( [ "$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 .) # Export binary (usage: docker build --target export --output build .)
FROM scratch AS export FROM scratch AS export
COPY --from=build /wibo/build/wibo .
COPY --from=build /usr/local/bin/wibo .
# Runnable container # Runnable container
FROM alpine:latest 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 WORKDIR /wibo
COPY . /wibo COPY . /wibo
# Build type (Release, Debug, RelWithDebInfo, MinSizeRel) # Build type (release, debug, release64, debug64)
ARG BUILD_TYPE=Release ARG BUILD_TYPE=release
# Enable link-time optimization (LTO) (AUTO, ON, OFF) # Enable link-time optimization (LTO) (AUTO, ON, OFF)
ARG ENABLE_LTO=AUTO ARG ENABLE_LTO=AUTO
@@ -43,22 +43,22 @@ ARG ENABLE_LTO=AUTO
# Version string (if not provided, defaults to "unknown") # Version string (if not provided, defaults to "unknown")
ARG WIBO_VERSION 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_AR:PATH=/usr/bin/llvm-ar \
-DCMAKE_RANLIB:PATH=/usr/bin/llvm-ranlib \ -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_ENABLE_LTO:STRING="$ENABLE_LTO" \
-DWIBO_VERSION:STRING="$WIBO_VERSION" \ -DWIBO_VERSION:STRING="$WIBO_VERSION" \
&& LIBCLANG_PATH=/usr/lib/llvm-18/lib cmake --build /wibo/build --verbose \ && LIBCLANG_PATH=/usr/lib/llvm-18/lib cmake --build --preset "$PRESET" --verbose \
&& ( [ "$BUILD_TYPE" != "Release" ] || strip -g /wibo/build/wibo ) && ( [ "$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 .) # Export binary (usage: docker build -f Dockerfile.ubuntu --target export --output dist .)
FROM scratch AS export FROM scratch AS export
COPY --from=build /wibo/build/wibo . COPY --from=build /usr/local/bin/wibo .
# Runnable container # Runnable container
FROM ubuntu:24.04 FROM ubuntu:24.04
COPY --from=build /wibo/build/wibo /usr/local/sbin/wibo COPY --from=build /usr/local/bin/wibo /usr/local/bin/wibo
CMD ["/usr/local/sbin/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) { if (ticks < 0.0L) {
return 0; return 0;
} }
if (ticks > static_cast<long double>(std::numeric_limits<LONGLONG>::max())) { if (ticks > static_cast<long double>(std::numeric_limits<long long>::max())) {
return std::numeric_limits<LONGLONG>::max(); return std::numeric_limits<long long>::max();
} }
return static_cast<LONGLONG>(ticks); return static_cast<LONGLONG>(ticks);
#endif #endif

View File

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

View File

@@ -26,6 +26,16 @@
#error "Unsupported platform" #error "Unsupported platform"
#endif #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__ #ifndef __USER_LABEL_PREFIX__
#define __USER_LABEL_PREFIX__ #define __USER_LABEL_PREFIX__
#endif #endif
@@ -46,7 +56,7 @@
#define ASM_SIZE_TYPE "long" #define ASM_SIZE_TYPE "long"
#endif #endif
#if __ELF__ #if __ELF__
#define ASM_RODATA_SECTION ".rodata" #define ASM_RODATA_SECTION ".section .rodata"
#else #else
#define ASM_RODATA_SECTION ".section __TEXT, __const" #define ASM_RODATA_SECTION ".section __TEXT, __const"
#endif #endif
@@ -68,6 +78,4 @@
static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(&GLUE(symbol, End)) - \ static_cast<std::size_t>(reinterpret_cast<std::uintptr_t>(&GLUE(symbol, End)) - \
reinterpret_cast<std::uintptr_t>(&symbol)) reinterpret_cast<std::uintptr_t>(&symbol))
#define INCLUDE_BIN_SPAN(symbol) std::span<const std::uint8_t>(symbol, INCLUDE_BIN_SIZE(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 .macro stubThunkX number
#if defined(__x86_64__) #if defined(__x86_64__)
ASM_GLOBAL(_Z9stubThunkILm\()\number\()EEvv, @function) #define STUB_THUNK_SYMBOL _Z9stubThunkILm\()\number\()EEvv
ASM_GLOBAL(STUB_THUNK_SYMBOL, @function)
#else #else
ASM_GLOBAL(_Z9stubThunkILj\()\number\()EEvv, @function) #define STUB_THUNK_SYMBOL _Z9stubThunkILj\()\number\()EEvv
ASM_GLOBAL(STUB_THUNK_SYMBOL, @function)
#endif #endif
pop eax pop eax
push \number 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)); TEST_CHECK_EQ(FALSE, gFns.time_to_seconds(&before_epoch, &seconds));
LARGE_INTEGER beyond_range = { 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)); TEST_CHECK_EQ(FALSE, gFns.time_to_seconds(&beyond_range, &seconds));
} }

View File

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