From b53b402f7df5eb1da5bd1f621efe2c034fecdab8 Mon Sep 17 00:00:00 2001 From: Adrien Bertrand Date: Mon, 16 Jan 2023 12:10:36 +0100 Subject: [PATCH] ci: windows: add GitHub Actions --- .../x64-windows-static-md-release.cmake | 4 + .github/workflows/build.linux.workflow.yml | 10 +- .github/workflows/build.mac.workflow.yml | 10 +- .github/workflows/build.windows.workflow.yml | 73 +++++++++++ .gitignore | 2 + CMakeLists.txt | 22 ++-- CMakePresets.json | 119 ++++++++++++++++++ libticables/trunk/CMakeLists.txt | 21 ++-- libticables/trunk/src/link_usb.cc | 2 +- libticables/trunk/src/ticables.cc | 8 +- libticables/trunk/src/win32/detect.cc | 6 +- libticables/trunk/tests/CMakeLists.txt | 8 +- libticalcs/trunk/CMakeLists.txt | 12 +- libticalcs/trunk/tests/CMakeLists.txt | 11 +- libtifiles/trunk/CMakeLists.txt | 2 +- libtifiles/trunk/tests/CMakeLists.txt | 2 +- vcpkg.json | 18 +++ 17 files changed, 293 insertions(+), 37 deletions(-) create mode 100644 .cmake/vcpkg-custom-triplets/x64-windows-static-md-release.cmake create mode 100644 .github/workflows/build.windows.workflow.yml create mode 100644 CMakePresets.json create mode 100644 vcpkg.json diff --git a/.cmake/vcpkg-custom-triplets/x64-windows-static-md-release.cmake b/.cmake/vcpkg-custom-triplets/x64-windows-static-md-release.cmake new file mode 100644 index 000000000..ed85753a8 --- /dev/null +++ b/.cmake/vcpkg-custom-triplets/x64-windows-static-md-release.cmake @@ -0,0 +1,4 @@ +set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_BUILD_TYPE release) \ No newline at end of file diff --git a/.github/workflows/build.linux.workflow.yml b/.github/workflows/build.linux.workflow.yml index 571cf09fb..1a4199e31 100644 --- a/.github/workflows/build.linux.workflow.yml +++ b/.github/workflows/build.linux.workflow.yml @@ -2,9 +2,9 @@ name: Build Linux on: push: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, feature/ci-windows ] pull_request: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, feature/ci-windows ] release: types: [published] @@ -60,10 +60,10 @@ jobs: cmake --build . --target install - name: Prepare install folder for upload - run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }} + run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps - name: Upload install folder uses: actions/upload-artifact@v3 with: - name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }} - path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }}/ + name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps + path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps/ diff --git a/.github/workflows/build.mac.workflow.yml b/.github/workflows/build.mac.workflow.yml index 7dc0d941a..e4970e9a0 100644 --- a/.github/workflows/build.mac.workflow.yml +++ b/.github/workflows/build.mac.workflow.yml @@ -2,9 +2,9 @@ name: Build macOS on: push: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, feature/ci-windows ] pull_request: - branches: [ master, experimental, experimental2 ] + branches: [ master, experimental, experimental2, feature/ci-windows ] release: types: [published] @@ -61,10 +61,10 @@ jobs: cmake --build . --target install - name: Prepare install folder for upload - run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }} + run: mv prefix tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps - name: Upload install folder uses: actions/upload-artifact@v3 with: - name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }} - path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps_${{ github.sha }}/ + name: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps + path: tilibs_${{ matrix.os }}_${{ matrix.deps_type }}Deps/ diff --git a/.github/workflows/build.windows.workflow.yml b/.github/workflows/build.windows.workflow.yml new file mode 100644 index 000000000..c32a1a94d --- /dev/null +++ b/.github/workflows/build.windows.workflow.yml @@ -0,0 +1,73 @@ +name: Build Windows + +on: + push: + branches: [ master, feature/github-actions, feature/ci-windows ] + pull_request: + branches: [ master, feature/github-actions, feature/ci-windows ] + release: + types: [published] + +jobs: + build: + name: "Build: ${{ matrix.arch }} - ${{ matrix.deps_type }} deps" + runs-on: windows-latest + strategy: + fail-fast: false + matrix: + arch: [x64] + config: [Release,ReleaseStatic] + include: + - arch: x64 + arch_name: 64-bit + arch_suffix: "64" + - config: Release + deps_type: shared + - config: ReleaseStatic + deps_type: static + + steps: + - name: Checkout Git Repo + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Install latest CMake + uses: lukka/get-cmake@9781783c006d9d607cb391b971a1dcbed768a25a # latest as of 2023-11-12 + + - name: Restore artifacts, or setup vcpkg (do not install any package) + uses: lukka/run-vcpkg@6fe69898af670ac05f4a8427cc5cff4fb361cee5 # latest as of 2023-11-12 + with: + vcpkgGitCommitId: '61f610845fb206298a69f708104a51d651872877' # latest as of 2023-11-12 + prependedCacheKey: '${{ matrix.deps_type }}Deps' + + - name: Create prefix folder + shell: cmd + run: mkdir prefix + + - name: Build tilibs + uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # latest as of 2023-11-12 + with: + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + configurePreset: '${{ matrix.arch }}-${{ matrix.config }}' + buildPreset: '${{ matrix.arch }}-${{ matrix.config }}' + env: + VCPKG_FORCE_SYSTEM_BINARIES: 1 + CMAKE_INSTALL_PREFIX_OVERRIDE: '${{ github.workspace }}/prefix' + + - name: Install tilibs + uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # latest as of 2023-11-12 + with: + cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt' + buildPreset: '${{ matrix.arch }}-${{ matrix.config }}' + buildPresetAdditionalArgs: "['--target install']" + + - name: Prepare install folder for upload + shell: cmd + run: rename prefix tilibs_windows_${{ matrix.deps_type }}Deps + + - name: Upload install folder + uses: actions/upload-artifact@v3 + with: + name: tilibs_windows_${{ matrix.deps_type }}Deps + path: tilibs_windows_${{ matrix.deps_type }}Deps diff --git a/.gitignore b/.gitignore index cc9372a8e..ab420ee72 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,7 @@ Thumbs.db .\#* \#*\# .idea/ +.vs/ [._]*.s[a-v][a-z] [._]*.sw[a-p] [._]s[a-rt-v][a-z] @@ -84,3 +85,4 @@ Session.vim # CMake cmake-build-*/ +tilibs.build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ff73c123b..a5d3ebe9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,20 +23,30 @@ project(tilibs C CXX) # - probably doesn't work very well with ancient toolchains or on uncommon OSes # # Notes: -# - this has been succesfully tested on recent macOS and Linux. +# - this has been succesfully tested on recent macOS, Linux, and Windows (with vcpkg). # - The TRY_STATIC_LIBS CMake option will try to build the libs (both shared and static) using as many static # dependent libraries as possible. # Let's note however that there is currently not much advantage in building that way, using shared libs is preferred, -# but at least you have the choice to do whatever you want should you ever really need a static build. +# but at least you have the choice to do whatever you want should you ever really need a static build (may be useful on Windows) # # In the future...: # - TODO: add support to build the ROM dumpers (will end up just launching the external tools...) # - WISH: do not hardcode the (auto-generated...) potfiles_* target names # - WISH: better expose each lib's generated install target (NTS: look at cmake's components feature?) # - WISH: provide Find* CMake modules for the libs themselves? -# - WISH: add support for Windows (that will probably be annoying) # +# In case there was an env-var override... +if(DEFINED ENV{CMAKE_INSTALL_PREFIX_OVERRIDE}) + set(CMAKE_INSTALL_PREFIX "$ENV{CMAKE_INSTALL_PREFIX_OVERRIDE}") +endif() +# Be sure to have the expected install prefix format +if(CMAKE_INSTALL_PREFIX) + file(TO_CMAKE_PATH "${CMAKE_INSTALL_PREFIX}" CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "CMAKE_INSTALL_PREFIX" FORCE) + message("CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}") +endif() + # Our modules list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/.cmake) file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/.cmake/*.cmake") @@ -61,7 +71,7 @@ else() endif() option(TRY_STATIC_LIBS "Build using as many static libs as possible" OFF) -if (VCPKG_TARGET_TRIPLET MATCHES "-static(-md|-release)?$") +if (VCPKG_TARGET_TRIPLET MATCHES "-static") if(NOT TRY_STATIC_LIBS) message(WARNING "Setting TRY_STATIC_LIBS to ON anyway due to static vcpkg target") set(TRY_STATIC_LIBS ON) @@ -72,10 +82,6 @@ if(TRY_STATIC_LIBS) message("Will try to build as statically as possible...") if(WIN32) set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) - if (NOT VCPKG_TARGET_TRIPLET MATCHES "-static-md$") - message("Using static MSVC runtime...") - set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - endif() else() set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..d4db9320e --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,119 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 21, + "patch": 1 + }, + "configurePresets": [ + { + "name": "ninja-vcpkg", + "hidden": true, + "generator": "Ninja", + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "binaryDir": "${sourceDir}/tilibs.build/${presetName}", + "installDir": "${sourceDir}/tilibs.build/${presetName}", + "cacheVariables": { + "VCPKG_MANIFEST_MODE": { + "type": "BOOL", + "value": "True" + }, + "VCPKG_MANIFEST_INSTALL": { + "type": "BOOL", + "value": "True" + } + } + }, + { + "name": "ninja-vcpkg-x64", + "hidden": true, + "inherits": "ninja-vcpkg", + "architecture": { + "strategy": "external", + "value": "x64" + }, + "cacheVariables": { + "TRY_STATIC_LIBS": { + "type": "BOOL", + "value": "OFF" + }, + "VCPKG_TARGET_TRIPLET": { + "type": "STRING", + "value": "x64-windows-release" + } + } + }, + { + "name": "x64-Debug", + "inherits": "ninja-vcpkg-x64", + "cacheVariables": { + "CMAKE_BUILD_TYPE": { + "type": "STRING", + "value": "Debug" + } + } + }, + { + "name": "x64-ReleaseStatic", + "inherits": "ninja-vcpkg-x64", + "cacheVariables": { + "CMAKE_BUILD_TYPE": { + "type": "STRING", + "value": "Release" + }, + "TRY_STATIC_LIBS": { + "type": "BOOL", + "value": "ON" + }, + "VCPKG_HOST_TRIPLET": { + "type": "STRING", + "value": "x64-windows-static-md-release" + }, + "VCPKG_TARGET_TRIPLET": { + "type": "STRING", + "value": "x64-windows-static-md-release" + }, + "VCPKG_INSTALL_OPTIONS": { + "type": "STRING", + "value": "--allow-unsupported;--overlay-triplets=.cmake/vcpkg-custom-triplets" + } + } + }, + { + "name": "x64-ReleaseDynamic", + "inherits": "ninja-vcpkg-x64", + "cacheVariables": { + "CMAKE_BUILD_TYPE": { + "type": "STRING", + "value": "Release" + }, + "TRY_STATIC_LIBS": { + "type": "BOOL", + "value": "ON" + }, + "VCPKG_HOST_TRIPLET": { + "type": "STRING", + "value": "x64-windows-release" + }, + "VCPKG_TARGET_TRIPLET": { + "type": "STRING", + "value": "x64-windows-release" + } + } + } + ], + "buildPresets": [ + { + "name": "x64-Debug", + "configurePreset": "x64-Debug" + }, + { + "name": "x64-ReleaseStatic", + "configurePreset": "x64-ReleaseStatic" + }, + { + "name": "x64-ReleaseDynamic", + "configurePreset": "x64-ReleaseDynamic" + } + ] +} diff --git a/libticables/trunk/CMakeLists.txt b/libticables/trunk/CMakeLists.txt index ee5936aca..964733225 100644 --- a/libticables/trunk/CMakeLists.txt +++ b/libticables/trunk/CMakeLists.txt @@ -44,16 +44,26 @@ if(WIN32) endif() # external deps lookup -pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) +if(WIN32) + pkg_check_modules(DEPS REQUIRED glib-2.0) + list(APPEND DEPS_LIBRARIES "libusb0") + list(APPEND DEPS_STATIC_LIBRARIES "libusb0") +else() + pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) + # Needed for the .pc files configured in the function below. + set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") +endif() try_static_libs_if_needed() -# Needed for the .pc files configured in the function below. -set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") - # auto-creation of all targets with flags etc. create_targets_both_lib_types(ticables2) +if(NOT WIN32) + # additional internal defines + target_compile_definitions(ticables2_objlib PUBLIC HAVE_LIBUSB_1_0=1 HAVE_LIBUSB10_STRERROR=1 HAVE_TERMIOS_H=1) +endif() + set_target_properties(ticables2_shared PROPERTIES VERSION 8.0.0 SOVERSION 8) # Takes care of the i18n po/pot/gmo/mo files @@ -62,9 +72,6 @@ if(ENABLE_NLS) add_dependencies(ticables2_objlib potfiles_2) endif() -# additional internal defines -target_compile_definitions(ticables2_objlib PUBLIC HAVE_LIBUSB_1_0=1 HAVE_LIBUSB10_STRERROR=1 HAVE_TERMIOS_H=1) - # check includes for parallel and serial support if(LINUX) include(CheckIncludeFile) diff --git a/libticables/trunk/src/link_usb.cc b/libticables/trunk/src/link_usb.cc index 6ea82a053..dedbba492 100644 --- a/libticables/trunk/src/link_usb.cc +++ b/libticables/trunk/src/link_usb.cc @@ -27,7 +27,7 @@ #ifndef NO_CABLE_SLV -#if defined(__WIN32__) && !defined(__MINGW32__) +#if !defined(HAVE_LIBUSB_1_0) && defined(__WIN32__) && !defined(__MINGW32__) # define HAVE_LIBUSB #endif diff --git a/libticables/trunk/src/ticables.cc b/libticables/trunk/src/ticables.cc index a6da9faca..5f1837230 100644 --- a/libticables/trunk/src/ticables.cc +++ b/libticables/trunk/src/ticables.cc @@ -35,12 +35,12 @@ #include #endif -#ifdef _MSC_VER -# include "./win32/usb.h" +#if defined(HAVE_LIBUSB_1_0) +# include #elif defined(HAVE_LIBUSB) # include -#elif defined(HAVE_LIBUSB_1_0) -# include +#elif defined(_MSC_VER) +# include "./win32/usb.h" #endif #include "gettext.h" diff --git a/libticables/trunk/src/win32/detect.cc b/libticables/trunk/src/win32/detect.cc index 64f5671fb..6733c534d 100644 --- a/libticables/trunk/src/win32/detect.cc +++ b/libticables/trunk/src/win32/detect.cc @@ -91,8 +91,12 @@ int win32_check_rwp(void) int win32_check_libusb(void) { - if(usb_get_version() != NULL) +#ifdef HAVE_LIBUSB_1_0 + return 0; +#else + if (usb_get_version() != NULL) return 0; else return ERR_LIBUSBWIN32_NOT_PRESENT; +#endif // HAVE_LIBUSB_1_0 } diff --git a/libticables/trunk/tests/CMakeLists.txt b/libticables/trunk/tests/CMakeLists.txt index 8bec3ca99..efc737306 100644 --- a/libticables/trunk/tests/CMakeLists.txt +++ b/libticables/trunk/tests/CMakeLists.txt @@ -6,7 +6,13 @@ project(libticables2-tests add_executable(torture_ticables torture_ticables.c) add_executable(test_ticables_2 test_ticables_2.cc) -pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) +if(WIN32) + pkg_check_modules(DEPS REQUIRED glib-2.0) + list(APPEND DEPS_LIBRARIES "libusb0") + list(APPEND DEPS_STATIC_LIBRARIES "libusb0") +else() + pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16) +endif() foreach(tar torture_ticables test_ticables_2) target_compile_options(${tar} PRIVATE ${DEPS_CFLAGS}) diff --git a/libticalcs/trunk/CMakeLists.txt b/libticalcs/trunk/CMakeLists.txt index ab69e5a86..f9d120aa9 100644 --- a/libticalcs/trunk/CMakeLists.txt +++ b/libticalcs/trunk/CMakeLists.txt @@ -65,9 +65,17 @@ set(PUBLIC_HEADERS # external deps lookup if(TRY_STATIC_LIBS) # from libticables and libtifiles... - set(external_deps_if_static "libusb-1.0>=1.0.16" "libarchive") + if(WIN32) + set(external_deps_if_static "libarchive") + else() + set(external_deps_if_static "libusb-1.0>=1.0.16" "libarchive") + endif() +endif() +pkg_check_modules(DEPS REQUIRED glib-2.0 ${external_deps_if_static}) +if(WIN32) + list(APPEND DEPS_LIBRARIES "libusb0") + list(APPEND DEPS_STATIC_LIBRARIES "libusb0") endif() -pkg_check_modules(DEPS REQUIRED glib-2.0 zlib ${external_deps_if_static}) try_static_libs_if_needed() diff --git a/libticalcs/trunk/tests/CMakeLists.txt b/libticalcs/trunk/tests/CMakeLists.txt index 25e297130..649eebf74 100644 --- a/libticalcs/trunk/tests/CMakeLists.txt +++ b/libticalcs/trunk/tests/CMakeLists.txt @@ -6,7 +6,16 @@ project(libticalcs2-tests add_executable(torture_ticalcs torture_ticalcs.c) add_executable(test_ticalcs_2 test_ticalcs_2.cc) -pkg_check_modules(DEPS REQUIRED glib-2.0 libusb-1.0>=1.0.16 libarchive zlib) +if(WIN32) + pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) + list(APPEND DEPS_LIBRARIES "libusb0") + list(APPEND DEPS_STATIC_LIBRARIES "libusb0") +else() + pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive libusb-1.0>=1.0.16) + # Needed for the .pc files configured in the function below. + set(TICABLES_LIBUSB_REQUIRES_PRIVATE "libusb-1.0") +endif() + if(USE_ICONV) find_package(Iconv REQUIRED) # flags/link for external deps diff --git a/libtifiles/trunk/CMakeLists.txt b/libtifiles/trunk/CMakeLists.txt index cd31e9398..2277c419b 100644 --- a/libtifiles/trunk/CMakeLists.txt +++ b/libtifiles/trunk/CMakeLists.txt @@ -50,7 +50,7 @@ set(PUBLIC_HEADERS src/typesxx.h) # external deps lookup -pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive zlib) +pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) try_static_libs_if_needed() # auto-creation of all targets with flags etc., alongside with internal deps diff --git a/libtifiles/trunk/tests/CMakeLists.txt b/libtifiles/trunk/tests/CMakeLists.txt index 868f55290..27b3d87ee 100644 --- a/libtifiles/trunk/tests/CMakeLists.txt +++ b/libtifiles/trunk/tests/CMakeLists.txt @@ -6,7 +6,7 @@ project(libtifiles2-tests add_executable(torture_tifiles torture_tifiles.c) add_executable(test_tifiles_2 test_tifiles_2.cc) -pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive zlib) +pkg_check_modules(DEPS REQUIRED glib-2.0 libarchive) if(USE_ICONV) find_package(Iconv REQUIRED) # flags/link for external deps diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..233222abc --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "tilibs", + "version-string": "1.0", + "homepage": "https://github.com/debrouxl/tilibs", + "description": "libs to transfer things from/to TI graphing calculators", + "dependencies": [ + "bzip2", + "pkgconf", + { + "name": "libarchive", + "default-features": false + }, + "libusb-win32", + "glib", + "gettext" + ], + "builtin-baseline": "61f610845fb206298a69f708104a51d651872877" +}