From 52aa0a0cb8fc5980e8d18287b4e123d53b8a6c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hermann=20H=C3=B6hne?= Date: Sun, 11 Aug 2024 23:46:35 +0200 Subject: [PATCH] Link vcruntime140 statically. --- .github/workflows/build.yml | 10 +++++----- CMakeLists.txt | 4 ++++ README.md | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4688c87..e5a751a 100755 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,19 +27,19 @@ jobs: triplet: x86-windows-static token: ${{ github.token }} - # NOTE: Ninja does not support specifying an architecture + # NOTE: Ninja does not support specifying an architecture, so I am going with the default which seems to be MSBuild # NOTE: CMAKE_GENERATOR_PLATFORM must take WIN32, not x86 because consistency (thanks to https://stackoverflow.com/questions/28350214/#comment121308920_52846043 and https://github.com/microsoft/vcpkg/issues/15465) - name: Configure - run: cmake -DCMAKE_GENERATOR_PLATFORM=WIN32 -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static -DVCPKG_MANIFEST_MODE=OFF -DCMAKE_BUILD_TYPE=Debug -S . -B build + run: cmake -DCMAKE_GENERATOR_PLATFORM=WIN32 -DCMAKE_TOOLCHAIN_FILE="${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static -DVCPKG_MANIFEST_MODE=OFF -DCMAKE_BUILD_TYPE=Release -S . -B build - name: Build - run: cmake --build build + run: cmake --build build --config Release - name: Strip - run: strip -s build/Debug/libpresage.dll + run: strip -s build/Release/libpresage.dll - name: Upload uses: actions/upload-artifact@v4 with: - path: build/Debug/libpresage.dll + path: build/Release/libpresage.dll name: libpresage.dll diff --git a/CMakeLists.txt b/CMakeLists.txt index 4176d92..369b2a1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ FetchContent_MakeAvailable(Corrosion) set(Rust_PROFILE "release" CACHE STRING "Rust profile") set_property(CACHE Rust_PROFILE PROPERTY STRINGS "dev" "release") corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/rust/Cargo.toml PROFILE ${Rust_PROFILE}) +corrosion_add_target_rustflags(purple_presage_backend "-C target-feature=+crt-static") +# https://stackoverflow.com/questions/31770604/how-to-generate-statically-linked-executables +# maybe also look at https://github.com/chrisdenton/static_vcruntime # obtain version string from back-end metadata execute_process(COMMAND ${Rust_CARGO_CACHED} metadata --format-version 1 --no-deps --manifest-path ${CMAKE_CURRENT_SOURCE_DIR}/src/rust/Cargo.toml OUTPUT_VARIABLE BACKEND_METADATA) @@ -67,6 +70,7 @@ else() # gcc_s util rt pthread m dl c endif() set_property(TARGET ${TARGET_NAME} PROPERTY COMPILE_WARNING_AS_ERROR ON) # needs cmake 3.24, but is not critical +set_property(TARGET ${TARGET_NAME} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded") # link vcruntime140 release version statically, see https://cmake.org/cmake/help/latest/prop_tgt/MSVC_RUNTIME_LIBRARY.html target_compile_definitions(${TARGET_NAME} PRIVATE PLUGIN_VERSION=${PLUGIN_VERSION}) target_include_directories(${TARGET_NAME} PRIVATE ${PURPLE_INCLUDE_DIRS}) diff --git a/README.md b/README.md index 16a3d38..1bcaa2f 100755 --- a/README.md +++ b/README.md @@ -93,18 +93,20 @@ protoc needs to be in your PATH. You can install it with any method you like, in Same as Linux build instructions, but may need to modify the configuration: -1. Generate project: +1. Generate MSBuild project: - cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_GENERATOR_PLATFORM=WIN32 -DCMAKE_TOOLCHAIN_FILE="…/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static -DRust_CARGO_TARGET="i686-pc-windows-msvc" .. + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR_PLATFORM=WIN32 -DCMAKE_TOOLCHAIN_FILE="…/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x86-windows-static -DRust_CARGO_TARGET="i686-pc-windows-msvc" .. If necessary, the rust tool-chain version can be specified via `-DRust_TOOLCHAIN="1.75-i686-pc-windows-msvc"`. 2. Build, Install and Run: cmake --build . - cmake --install . --config Debug + cmake --install . --config Release cmake --build . --target run +When using the "Debug" configuration, the linker complains about mismatching configurations. The implications of this are unknown. + #### Notes purple-presage must be built with MSVC. MinGW's GCC encountered a number of issues such as [incompatibility with rustc versions newer than 1.69](https://github.com/rust-lang/rust/issues/112368) and not shipping libbcrypt by default.