mirror of
https://github.com/encounter/nod.git
synced 2026-07-10 12:18:48 -07:00
Add prebuilt CMake packages for libnod to releases
This commit is contained in:
@@ -9,9 +9,8 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
BUILD_PROFILE: release-lto
|
||||
CARGO_TARGET_DIR: target
|
||||
CARGO_INCREMENTAL: 0
|
||||
RUSTC_WRAPPER: sccache
|
||||
SCCACHE_GHA_ENABLED: "true"
|
||||
|
||||
jobs:
|
||||
check:
|
||||
@@ -31,8 +30,8 @@ jobs:
|
||||
with:
|
||||
toolchain: ${{ matrix.toolchain }}
|
||||
components: clippy
|
||||
- name: Cache Rust workspace
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Setup sccache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Cargo check
|
||||
run: cargo check --all-targets
|
||||
- name: Cargo clippy
|
||||
@@ -62,8 +61,8 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- name: Cache Rust workspace
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Setup sccache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Install cbindgen
|
||||
run: cargo install cbindgen
|
||||
- name: Generate header
|
||||
@@ -74,6 +73,8 @@ jobs:
|
||||
deny:
|
||||
name: Deny
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
RUSTC_WRAPPER: "" # sccache breaks cargo-deny
|
||||
strategy:
|
||||
matrix:
|
||||
checks:
|
||||
@@ -100,15 +101,18 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- name: Cache Rust workspace
|
||||
uses: Swatinem/rust-cache@v2
|
||||
- name: Setup sccache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Cargo test
|
||||
run: cargo test --release
|
||||
|
||||
build:
|
||||
name: Build nodtool
|
||||
env:
|
||||
BUILD_PROFILE: release-lto
|
||||
CARGO_BIN_NAME: nodtool
|
||||
CARGO_INCREMENTAL: 0
|
||||
CARGO_TARGET_DIR: target
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
@@ -169,10 +173,8 @@ jobs:
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
- name: Cache Rust workspace
|
||||
uses: Swatinem/rust-cache@v2
|
||||
with:
|
||||
key: ${{ matrix.target }}
|
||||
- name: Setup sccache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Cargo build
|
||||
run: >
|
||||
cargo ${{ matrix.build }} --profile ${{ env.BUILD_PROFILE }} --target ${{ matrix.target }}
|
||||
@@ -186,11 +188,49 @@ jobs:
|
||||
${{ env.CARGO_TARGET_DIR }}/${{ matrix.target }}/${{ env.BUILD_PROFILE }}/${{ env.CARGO_BIN_NAME }}.exe
|
||||
if-no-files-found: error
|
||||
|
||||
build-libs:
|
||||
name: Build libraries
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- platform: ubuntu-latest
|
||||
name: linux-x86_64
|
||||
- platform: windows-latest
|
||||
name: windows-x86_64
|
||||
- platform: macos-latest
|
||||
name: macos-arm64
|
||||
fail-fast: false
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Rust toolchain
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
- name: Setup sccache
|
||||
uses: mozilla-actions/sccache-action@v0.0.9
|
||||
- name: Setup MSVC environment
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
if: startsWith(matrix.platform, 'windows-')
|
||||
- name: Configure
|
||||
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
|
||||
- name: Build
|
||||
run: cmake --build build --config Release
|
||||
- name: Install
|
||||
run: cmake --install build --prefix install --config Release
|
||||
- name: Package
|
||||
run: tar czf libnod-${{ matrix.name }}.tar.gz -C install .
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: libnod-${{ matrix.name }}
|
||||
path: libnod-${{ matrix.name }}.tar.gz
|
||||
if-no-files-found: error
|
||||
|
||||
release:
|
||||
name: Release
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ build ]
|
||||
needs: [ build, build-libs ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
@@ -218,6 +258,11 @@ jobs:
|
||||
for dir in */; do
|
||||
for file in "$dir"*; do
|
||||
base=$(basename "$file")
|
||||
# .tar.gz files (lib packages) are already named correctly
|
||||
if [[ "$base" == *.tar.gz ]]; then
|
||||
mv "$file" "../out/$base"
|
||||
continue
|
||||
fi
|
||||
name="${base%.*}"
|
||||
ext="${base##*.}"
|
||||
if [ "$ext" = "$base" ]; then
|
||||
|
||||
+106
-2
@@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.23)
|
||||
project(nod C)
|
||||
project(nod VERSION 2.0.0 LANGUAGES C)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
@@ -8,9 +8,14 @@ option(NOD_COMPRESS_LZMA "Enable LZMA/LZMA2 support" ON)
|
||||
option(NOD_COMPRESS_ZLIB "Enable zlib/deflate support" ON)
|
||||
option(NOD_COMPRESS_ZSTD "Enable Zstandard support" ON)
|
||||
option(NOD_THREADING "Enable threaded processing support" ON)
|
||||
option(NOD_USE_CMAKE_COMPRESSION
|
||||
"Use CMake-provided compression libraries instead of Cargo vendoring. \
|
||||
When OFF (default), Cargo builds and statically links compression libraries \
|
||||
via -sys crates. When ON, compression libraries are found/built by CMake \
|
||||
and linked externally (useful when the parent project shares these libraries)."
|
||||
OFF)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||
include(NodCompressionDeps)
|
||||
|
||||
# Fetch Corrosion, allowing us to import the nod-ffi crate as a CMake target.
|
||||
FetchContent_Declare(
|
||||
@@ -20,7 +25,12 @@ FetchContent_Declare(
|
||||
)
|
||||
FetchContent_MakeAvailable(Corrosion)
|
||||
|
||||
# Build the feature list based on the selected compression mode.
|
||||
set(NOD_FEATURES)
|
||||
if (NOD_USE_CMAKE_COMPRESSION)
|
||||
# CMake-provided compression: use base features (raw #[link] FFI).
|
||||
# NodCompressionDeps.cmake handles finding/building the C libraries
|
||||
# and linking them to the nod_ffi target.
|
||||
if (NOD_COMPRESS_BZIP2)
|
||||
list(APPEND NOD_FEATURES compress-bzip2)
|
||||
endif()
|
||||
@@ -33,6 +43,22 @@ endif()
|
||||
if (NOD_COMPRESS_ZSTD)
|
||||
list(APPEND NOD_FEATURES compress-zstd)
|
||||
endif()
|
||||
else()
|
||||
# Cargo-vendored compression (default): -sys crates build and statically
|
||||
# link the C libraries within Cargo. No CMake compression deps needed.
|
||||
if (NOD_COMPRESS_BZIP2)
|
||||
list(APPEND NOD_FEATURES compress-bzip2-static)
|
||||
endif()
|
||||
if (NOD_COMPRESS_LZMA)
|
||||
list(APPEND NOD_FEATURES compress-lzma-static)
|
||||
endif()
|
||||
if (NOD_COMPRESS_ZLIB)
|
||||
list(APPEND NOD_FEATURES compress-zlib-static)
|
||||
endif()
|
||||
if (NOD_COMPRESS_ZSTD)
|
||||
list(APPEND NOD_FEATURES compress-zstd-static)
|
||||
endif()
|
||||
endif()
|
||||
if (NOD_THREADING)
|
||||
list(APPEND NOD_FEATURES threading)
|
||||
endif()
|
||||
@@ -51,6 +77,11 @@ corrosion_import_crate(
|
||||
${NOD_IMPORT_ARGS}
|
||||
)
|
||||
|
||||
# When using CMake-provided compression, find/build the C libraries
|
||||
# and link them to the Rust target.
|
||||
if (NOD_USE_CMAKE_COMPRESSION)
|
||||
include(NodCompressionDeps)
|
||||
|
||||
if (NOD_COMPRESS_BZIP2)
|
||||
nod_require_bzip2(_nod_bzip2_target)
|
||||
target_link_libraries(nod_ffi INTERFACE "${_nod_bzip2_target}")
|
||||
@@ -99,6 +130,7 @@ if (NOD_COMPRESS_ZSTD)
|
||||
endif()
|
||||
add_dependencies(_cargo-build_nod_ffi "${_nod_zstd_rust_link}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_sources(nod_ffi INTERFACE
|
||||
FILE_SET HEADERS
|
||||
@@ -109,6 +141,78 @@ target_sources(nod_ffi INTERFACE
|
||||
# Create a namespace alias for the library target.
|
||||
add_library(nod::nod ALIAS nod_ffi)
|
||||
|
||||
# Install
|
||||
include(GNUInstallDirs)
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
set(_NOD_INSTALL_DEFAULT ON)
|
||||
else ()
|
||||
set(_NOD_INSTALL_DEFAULT OFF)
|
||||
endif ()
|
||||
option(NOD_ENABLE_INSTALL "Generate install targets" ${_NOD_INSTALL_DEFAULT})
|
||||
|
||||
if (NOD_ENABLE_INSTALL)
|
||||
# Corrosion's install doesn't generate proper IMPORTED targets for consumers,
|
||||
# so we install the library files directly and generate our own CMake config.
|
||||
|
||||
# Shared library
|
||||
if (TARGET nod_ffi-shared)
|
||||
if (WIN32)
|
||||
# DLL to bin/
|
||||
install(FILES "$<TARGET_FILE:nod_ffi-shared>"
|
||||
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
RENAME "${CMAKE_SHARED_LIBRARY_PREFIX}nod${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
||||
)
|
||||
# Import library to lib/
|
||||
install(FILES "$<TARGET_LINKER_FILE:nod_ffi-shared>"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RENAME "${CMAKE_IMPORT_LIBRARY_PREFIX}nod${CMAKE_IMPORT_LIBRARY_SUFFIX}"
|
||||
)
|
||||
else()
|
||||
install(FILES "$<TARGET_FILE:nod_ffi-shared>"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RENAME "${CMAKE_SHARED_LIBRARY_PREFIX}nod${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Static library
|
||||
if (TARGET nod_ffi-static)
|
||||
if (MSVC)
|
||||
# On MSVC, use nod_static to avoid collision with the DLL import library
|
||||
set(_nod_static_name "nod_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
set(_nod_static_name "${CMAKE_STATIC_LIBRARY_PREFIX}nod${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
endif()
|
||||
install(FILES "$<TARGET_FILE:nod_ffi-static>"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RENAME "${_nod_static_name}"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Header
|
||||
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/nod-ffi/include/nod.h"
|
||||
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
|
||||
# Generate CMake config files for find_package(nod)
|
||||
include(CMakePackageConfigHelpers)
|
||||
configure_package_config_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/nodConfig.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/nodConfig.cmake"
|
||||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/nod"
|
||||
)
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/nodConfigVersion.cmake"
|
||||
VERSION "${PROJECT_VERSION}"
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
install(FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/nodConfig.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/nodConfigVersion.cmake"
|
||||
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/nod"
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
add_subdirectory(nod-ffi/examples)
|
||||
endif()
|
||||
|
||||
Generated
+10
-10
@@ -75,9 +75,9 @@ checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.11.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96eb4cdd6cf1b31d671e9efe75c5d1ec614776856cefbe109ca373554a6d514f"
|
||||
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
@@ -115,9 +115,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cbc"
|
||||
version = "0.2.0-rc.3"
|
||||
version = "0.2.0-rc.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85742c5f1d0dda799d2e582c76b82b817d3e4d6434dd285e48e90ed0c963b667"
|
||||
checksum = "ab1412b9ae2463ede01f1e591412dfbcfeacecf40e8c4c3e0655814c19065c38"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
@@ -142,9 +142,9 @@ checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64727038c8c5e2bb503a15b9f5b9df50a1da9a33e83e1f93067d914f2c6604a5"
|
||||
checksum = "e34d8227fe1ba289043aeb13792056ff80fd6de1a9f49137a5f499de8e8c78ea"
|
||||
dependencies = [
|
||||
"crypto-common",
|
||||
"inout",
|
||||
@@ -204,18 +204,18 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "211f05e03c7d03754740fd9e585de910a095d6b99f8bcfffdef8319fa02a8331"
|
||||
checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710"
|
||||
dependencies = [
|
||||
"hybrid-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.11.0"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8bf3682cdec91817be507e4aa104314898b95b84d74f3d43882210101a545b6"
|
||||
checksum = "285743a676ccb6b3e116bc14cc69319b957867930ae9c4822f8e0f54509d7243"
|
||||
dependencies = [
|
||||
"block-buffer",
|
||||
"crypto-common",
|
||||
|
||||
@@ -3,13 +3,9 @@ members = ["nod", "nod-ffi", "nodtool"]
|
||||
default-members = ["nod", "nodtool"]
|
||||
resolver = "3"
|
||||
|
||||
[profile.release]
|
||||
debug = 1
|
||||
|
||||
[profile.release-lto]
|
||||
inherits = "release"
|
||||
lto = "fat"
|
||||
strip = "debuginfo"
|
||||
codegen-units = 1
|
||||
|
||||
[workspace.package]
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
set(_nod_libdir "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@")
|
||||
set(_nod_incdir "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@")
|
||||
|
||||
if (NOT TARGET nod::nod_shared AND NOT TARGET nod::nod_static)
|
||||
# Shared library
|
||||
if (WIN32)
|
||||
set(_nod_dll "${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_BINDIR@/${CMAKE_SHARED_LIBRARY_PREFIX}nod${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
set(_nod_implib "${_nod_libdir}/${CMAKE_IMPORT_LIBRARY_PREFIX}nod${CMAKE_IMPORT_LIBRARY_SUFFIX}")
|
||||
if (EXISTS "${_nod_dll}")
|
||||
add_library(nod::nod_shared SHARED IMPORTED)
|
||||
set_target_properties(nod::nod_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${_nod_dll}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_nod_incdir}"
|
||||
)
|
||||
if (EXISTS "${_nod_implib}")
|
||||
set_target_properties(nod::nod_shared PROPERTIES
|
||||
IMPORTED_IMPLIB "${_nod_implib}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(_nod_shared "${_nod_libdir}/${CMAKE_SHARED_LIBRARY_PREFIX}nod${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
||||
if (EXISTS "${_nod_shared}")
|
||||
add_library(nod::nod_shared SHARED IMPORTED)
|
||||
set_target_properties(nod::nod_shared PROPERTIES
|
||||
IMPORTED_LOCATION "${_nod_shared}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_nod_incdir}"
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Static library
|
||||
if (MSVC)
|
||||
set(_nod_static "${_nod_libdir}/nod_static${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
else()
|
||||
set(_nod_static "${_nod_libdir}/${CMAKE_STATIC_LIBRARY_PREFIX}nod${CMAKE_STATIC_LIBRARY_SUFFIX}")
|
||||
endif()
|
||||
if (EXISTS "${_nod_static}")
|
||||
add_library(nod::nod_static STATIC IMPORTED)
|
||||
set_target_properties(nod::nod_static PROPERTIES
|
||||
IMPORTED_LOCATION "${_nod_static}"
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_nod_incdir}"
|
||||
)
|
||||
endif()
|
||||
|
||||
# Default nod::nod target (respects BUILD_SHARED_LIBS)
|
||||
if (BUILD_SHARED_LIBS AND TARGET nod::nod_shared)
|
||||
add_library(nod::nod INTERFACE IMPORTED)
|
||||
set_target_properties(nod::nod PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES nod::nod_shared
|
||||
)
|
||||
elseif (TARGET nod::nod_static)
|
||||
add_library(nod::nod INTERFACE IMPORTED)
|
||||
set_target_properties(nod::nod PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES nod::nod_static
|
||||
)
|
||||
elseif (TARGET nod::nod_shared)
|
||||
add_library(nod::nod INTERFACE IMPORTED)
|
||||
set_target_properties(nod::nod PROPERTIES
|
||||
INTERFACE_LINK_LIBRARIES nod::nod_shared
|
||||
)
|
||||
else()
|
||||
set(nod_FOUND FALSE)
|
||||
if (nod_FIND_REQUIRED)
|
||||
message(FATAL_ERROR "nod library not found in ${_nod_libdir}")
|
||||
endif()
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
unset(_nod_libdir)
|
||||
unset(_nod_incdir)
|
||||
|
||||
check_required_components(nod)
|
||||
@@ -17,9 +17,17 @@ crate-type = ["cdylib", "staticlib"]
|
||||
[features]
|
||||
default = ["compress-bzip2", "compress-lzma", "compress-zlib", "compress-zstd", "threading"]
|
||||
compress-bzip2 = ["nod/compress-bzip2"]
|
||||
compress-bzip2-vendored = ["nod/compress-bzip2-vendored"]
|
||||
compress-bzip2-static = ["nod/compress-bzip2-static"]
|
||||
compress-lzma = ["nod/compress-lzma"]
|
||||
compress-lzma-vendored = ["nod/compress-lzma-vendored"]
|
||||
compress-lzma-static = ["nod/compress-lzma-static"]
|
||||
compress-zlib = ["nod/compress-zlib"]
|
||||
compress-zlib-vendored = ["nod/compress-zlib-vendored"]
|
||||
compress-zlib-static = ["nod/compress-zlib-static"]
|
||||
compress-zstd = ["nod/compress-zstd"]
|
||||
compress-zstd-vendored = ["nod/compress-zstd-vendored"]
|
||||
compress-zstd-static = ["nod/compress-zstd-static"]
|
||||
threading = ["nod/threading"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
Reference in New Issue
Block a user