Skip to content

Commit

Permalink
Merge pull request #154 from nathan818fr/release-workflow
Browse files Browse the repository at this point in the history
WIP: Release pre-built binaries
  • Loading branch information
rdbo authored Dec 7, 2023
2 parents adcc06c + cd6f347 commit b946d9c
Show file tree
Hide file tree
Showing 12 changed files with 578 additions and 31 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---

name: Release

on:
push:
tags:
- '*'
workflow_dispatch:
inputs:
checkout-branch:
description: 'The branch or tag to checkout (same as workflow if not specified)'
required: false
targets:
description: 'The targets to build (regex, all if not specified)'
required: false

jobs:

prepare:
runs-on: ubuntu-latest
outputs:
artifact-version: ${{ steps.set-version.outputs.artifact-version }}
release: ${{ steps.set-version.outputs.release }}
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Set version
id: set-version
run: |
if [[ "$GITHUB_EVENT_NAME" == 'push' && "$GITHUB_REF_TYPE" == 'tag' ]]; then
artifact_version=${GITHUB_REF_NAME}
release=true
else
artifact_version='test'
release=false
fi
printf 'Artifact version: %s\n' "$artifact_version"
printf 'artifact-version=%s\n' "$artifact_version" >> "$GITHUB_OUTPUT"
printf 'Release: %s\n' "$release"
printf 'release=%s\n' "$release" >> "$GITHUB_OUTPUT"
- name: Set matrix
id: set-matrix
run: |
matrix=$(jq -Mcs \
--arg filter "^${INPUT_TARGETS:-.*}$" \
'{include: [.[] | select(.target|test($filter))]}' \
<<<'
{"target": "x86_64-linux-gnu-shared", "runs-on": "ubuntu-latest"}
{"target": "x86_64-linux-gnu-static", "runs-on": "ubuntu-latest"}
{"target": "x86_64-linux-musl-shared", "runs-on": "ubuntu-latest"}
{"target": "x86_64-linux-musl-static", "runs-on": "ubuntu-latest"}
{"target": "i686-windows-msvc-shared-md", "runs-on": "windows-2019"}
{"target": "i686-windows-msvc-static-md", "runs-on": "windows-2019"}
{"target": "i686-windows-msvc-static-mt", "runs-on": "windows-2019"}
{"target": "x86_64-windows-msvc-shared-md", "runs-on": "windows-2019"}
{"target": "x86_64-windows-msvc-static-md", "runs-on": "windows-2019"}
{"target": "x86_64-windows-msvc-static-mt", "runs-on": "windows-2019"}
{"target": "aarch64-windows-msvc-shared-md", "runs-on": "windows-2022"}
{"target": "aarch64-windows-msvc-static-md", "runs-on": "windows-2022"}
{"target": "aarch64-windows-msvc-static-mt", "runs-on": "windows-2022"}
'
)
printf 'Matrix: %s\n' "$(jq <<< "$matrix")"
printf 'matrix=%s\n' "$matrix" >> "$GITHUB_OUTPUT"
env:
INPUT_TARGETS: ${{ inputs.targets }}

build:
needs: prepare
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.checkout-branch }}
submodules: true
- name: Build
run: ./tools/build-release.sh "$BUILD_TARGETS"
shell: bash
env:
BUILD_TARGETS: ${{ matrix.target }}
LIBMEM_BUILD_OUT_DIR: out/libmem-${{ needs.prepare.outputs.artifact-version }}-${{ matrix.target }}
MSYS: 'winsymlinks:sys' # fix symlink issues when cloning on Windows
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: libmem-${{ needs.prepare.outputs.artifact-version }}-${{ matrix.target }}
path: out/libmem-${{ needs.prepare.outputs.artifact-version }}-${{ matrix.target }}.tar.gz

release:
needs: [prepare, build]
if: needs.prepare.outputs.release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write # allows the action to create a release
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
omitBody: true
prerelease: true
artifacts: libmem-*/libmem-*.tar.gz
artifactContentType: application/gzip
artifactErrorsFailBuild: true
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
path = external/injector
url = https://github.com/rdbo/injector
branch = rdbo-flatpak-sandbox-fix
[submodule "vcvars-bash"]
path = external/vcvars-bash
url = https://github.com/nathan818fr/vcvars-bash.git
branch = master
47 changes: 40 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ endif()

if (LIBMEM_BUILD_STATIC)
add_library(libmem STATIC ${LIBMEM_SRC})
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
add_custom_command(
TARGET libmem POST_BUILD
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND sh ${PROJECT_SOURCE_DIR}/tools/makebundle.sh
)
endif()
else()
add_library(libmem SHARED ${LIBMEM_SRC})
endif()
Expand Down Expand Up @@ -175,6 +168,46 @@ if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
endif()

target_link_libraries(libmem ${LIBMEM_DEPS})
if(LIBMEM_BUILD_STATIC)
# Create a bundled static library containing all dependencies (to mimic the shared library behavior)
set_target_properties(libmem PROPERTIES OUTPUT_NAME "libmem_partial")
set(libmem_bundle_files "$<TARGET_FILE:libmem>")

get_target_property(libmem_link_libraries libmem LINK_LIBRARIES)
foreach(libmem_link_library IN LISTS libmem_link_libraries)
if(TARGET "${libmem_link_library}")
list(APPEND libmem_bundle_files "$<TARGET_FILE:${libmem_link_library}>")
endif()
endforeach()

if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL Windows AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
file(WRITE "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "CREATE liblibmem.a\n" )
foreach(libmem_bundle_file IN LISTS libmem_bundle_files)
file(APPEND "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "ADDLIB ${libmem_bundle_file}\n")
endforeach()
file(APPEND "${CMAKE_BINARY_DIR}/liblibmem.ar.in" "SAVE\nEND\n")
file(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/liblibmem.ar" INPUT "${CMAKE_BINARY_DIR}/liblibmem.ar.in")

add_custom_command(
TARGET libmem POST_BUILD
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMAND "${CMAKE_AR}" -M < "${CMAKE_BINARY_DIR}/liblibmem.ar"
COMMENT "Bundling liblibmem.a"
VERBATIM
)
elseif(MSVC)
find_program(LIB_EXECUTABLE lib)
add_custom_command(
TARGET libmem POST_BUILD
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
COMMAND "${LIB_EXECUTABLE}" /NOLOGO /OUT:libmem.lib ${libmem_bundle_files}
COMMENT "Bundling libmem.lib"
VERBATIM
)
else()
message(WARNING "Static library bundling not supported on this platform")
endif()
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Windows OR ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL CYGWIN)
Expand Down
25 changes: 24 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ set(CAPSTONE_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DCAPSTONE_ARCHITECTURE_DEFAULT=ON
-DCAPSTONE_BUILD_TESTS=OFF
-DCAPSTONE_BUILD_CSTOOL=OFF
-DCAPSTONE_INSTALL=OFF
-DCAPSTONE_BUILD_SHARED=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCAPSTONE_ARCHITECTURE_DEFAULT=OFF
-DCAPSTONE_BUILD_STATIC_RUNTIME=OFF
)
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
if(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreaded" OR ${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreadedDebug")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=ON)
else()
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=OFF)
endif()
else()
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DCAPSTONE_BUILD_STATIC_RUNTIME=OFF)
endif()
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(CAPSTONE_CMAKE_ARGS ${CAPSTONE_CMAKE_ARGS} -DCAPSTONE_ARM64_SUPPORT=ON)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
Expand All @@ -27,9 +36,22 @@ set(KEYSTONE_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DKEYSTONE_BUILD_STATIC_RUNTIME=OFF
)
if(DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
string(TOUPPER "LLVM_USE_CRT_${CMAKE_BUILD_TYPE}" LLVM_USE_CRT_VAR)
if(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreaded")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MT)
elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreadedDebug")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MTd)
elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreadedDLL")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MD)
elseif(${CMAKE_MSVC_RUNTIME_LIBRARY} STREQUAL "MultiThreadedDebugDLL")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -D${LLVM_USE_CRT_VAR}=MDd)
endif()
endif()
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
set(KEYSTONE_CMAKE_ARGS ${KEYSTONE_CMAKE_ARGS} -DLLVM_TARGETS_TO_BUILD=AArch64)
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
Expand All @@ -45,6 +67,7 @@ set(LIEF_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_MSVC_RUNTIME_LIBRARY=${CMAKE_MSVC_RUNTIME_LIBRARY}
-DLIEF_USE_CCACHE=OFF
-DLIEF_ENABLE_JSON=OFF
-DLIEF_FROZEN_ENABLED=OFF
Expand Down
1 change: 1 addition & 0 deletions external/vcvars-bash
Submodule vcvars-bash added at 7041b8
Loading

0 comments on commit b946d9c

Please sign in to comment.