Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: #40 Refactoring for code quality and memory safety (TEST PR) #41

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/scripts/build-ctest-review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = async ({github, context, pull_number, status, log}) => {
const reviews = await github.rest.pulls.listReviews({
pull_number: pull_number,
owner: context.repo.owner,
repo: context.repo.repo,
});

console.log(reviews);

for (let review of reviews.data) {
if (review.user.login === 'github-actions' && review.state === 'COMMENTED') {
await github.rest.pulls.dismissReview({
pull_number: pull_number,
owner: context.repo.owner,
repo: context.repo.repo,
review_id: review.id
});
}
}

await github.rest.pulls.createReview({
pull_number: pull_number,
owner: context.repo.owner,
repo: context.repo.repo,
body: (status === 'success' ? '😍 Tests passed!' : '😨 Tests failed!') + '\n\n```\n' + log.replaceAll('%%%', "\n") + '\n```',
event: (status === 'success' ? 'COMMENT' : 'REQUEST_CHANGES')
});
}
78 changes: 76 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ on:
SSH_KEY:
required: false
description: SSH private key for pushing version changes
SONAR_TOKEN:
required: false
description: SonarCloud token for code analysis
SONAR_HOST_URL:
required: false
description: SonarCloud host URL
inputs:
cmake-preset:
required: true
Expand Down Expand Up @@ -38,15 +44,32 @@ on:
required: false
type: string
default: main
enable-sonar:
required: false
type: boolean
default: false
enable-tests:
required: false
type: boolean
default: true
notify-tests:
required: false
type: boolean
default: false

jobs:
build:
name: MSVC / Windows 2022
runs-on: windows-2022
permissions:
pull-requests: write
env:
BUILD_WRAPPER_OUT_DIR: build_wrapper_output
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x86
Expand Down Expand Up @@ -86,8 +109,59 @@ jobs:
}
- name: CMake Configure
run: cmake --preset ${{ inputs.cmake-preset }}
- name: Ninja Build
run: ninja -C out/build/${{ inputs.cmake-preset }} -j 20
- name: CMake Build
if: ${{ inputs.enable-sonar == false }}
run: |
cmake --build out/build/${{ inputs.cmake-preset }} --target zbassmusic_vdf -j 16
- name: Install Sonar
if: ${{ inputs.enable-sonar == true }}
run: |
Invoke-WebRequest https://sonarcloud.io/static/cpp/build-wrapper-win-x86.zip -OutFile build-wrapper-win-x86.zip
Expand-Archive build-wrapper-win-x86.zip -Destination .
Invoke-WebRequest https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-6.0.0.4432-windows.zip -OutFile sonar-scanner-cli-6.0.0.4432-windows.zip
Expand-Archive sonar-scanner-cli-6.0.0.4432-windows.zip -Destination .
- name: CMake Build (Sonar Wrapper)
if: ${{ inputs.enable-sonar == true }}
run: |
./build-wrapper-win-x86/build-wrapper-win-x86-64.exe --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build out/build/${{ inputs.cmake-preset }} --target zbassmusic_vdf -j 16
- name: Sonar Scanner
if: ${{ inputs.enable-sonar == true }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
run: |
./sonar-scanner-6.0.0.4432-windows/bin/sonar-scanner.bat --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
- name: CTest
id: tests
if: ${{ inputs.enable-tests == true }}
run: |
$status = $false;
cmake --build out/build/${{ inputs.cmake-preset }} --target tests -j 16
if (ctest --test-dir out/build/${{ inputs.cmake-preset }}/tests -j 16) {
echo "tests=success" >> $env:GITHUB_OUTPUT
$status = $true;
} else {
echo "tests=failed" >> $env:GITHUB_OUTPUT
}
$testsLog = (Get-Content -Path out/build/${{ inputs.cmake-preset }}/tests/Testing/Temporary/LastTest.log) -join "%%%"
echo "tests_log=${testsLog}" >> $env:GITHUB_OUTPUT
cat out/build/${{ inputs.cmake-preset }}/tests/Testing/Temporary/LastTest.log
if (-not $status) {
exit -1
}
- name: CTest Result PR
if: ${{ inputs.enable-tests == true && inputs.notify-tests == true && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const pull_number = ${{ github.event.number }};
const status = '${{ steps.tests.outputs.tests }}';
const log = '${{ steps.tests.outputs.tests_log }}';
require('./.github/scripts/build-ctest-review.js')({
github, context, pull_number, status, log
});
- name: CMake Install
run: cmake --install out/build/${{ inputs.cmake-preset }} --prefix out/install/${{ inputs.cmake-preset }}
- name: Archive DLL
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
pull_request:
branches: [ "main", "dev" ]
push:
branches: [ "main", "dev", "gh_actions" ]
branches: [ "main", "dev", "feature/*", "bugfix/*" ]
paths-ignore:
- 'README.md'
- 'docs/**'
Expand All @@ -14,11 +14,16 @@ jobs:
build-debug:
name: Build Debug
uses: ./.github/workflows/build.yml
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
with:
cmake-preset: x86-debug
upload-artifact-dll: debug-dll
upload-artifact-dll-pdb: debug-dll-pdb
upload-artifact-vdf: debug-vdf
enable-sonar: true
notify-tests: true

build-release:
name: Build Release
Expand All @@ -29,9 +34,9 @@ jobs:
upload-artifact-vdf: release-vdf

build-release-pdb:
name: Build Release (Debug Symbols)
name: Build RelWithDebInfo
uses: ./.github/workflows/build.yml
with:
cmake-preset: x86-release-pdb
upload-artifact-dll-pdb: release-dll-pdb
upload-artifact-vdf: release-vdf-pdb
cmake-preset: x86-relwithdebinfo
upload-artifact-dll-pdb: relwithdebinfo-dll
upload-artifact-vdf: relwithdebinfo-vdf
24 changes: 12 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ jobs:
project-version: ${{ github.ref_name }}
push-version-commit: true

build-release-pdb:
name: Build Release (Debug Symbols)
build-relwithdebinfo:
name: Build RelWithDebInfo
uses: ./.github/workflows/build.yml
with:
cmake-preset: x86-release-pdb
upload-artifact-dll-pdb: release-dll-pdb
upload-artifact-vdf: release-vdf-pdb
cmake-preset: x86-relwithdebinfo
upload-artifact-dll-pdb: relwithdebinfo-dll
upload-artifact-vdf: relwithdebinfo-vdf
project-version: ${{ github.ref_name }}

publish:
name: Publish Release
runs-on: windows-2022
needs:
- build-release
- build-release-pdb
- build-relwithdebinfo
steps:
- name: Download Release DLL
uses: actions/download-artifact@v4
Expand All @@ -48,13 +48,13 @@ jobs:
- name: Download Release DLL PDB
uses: actions/download-artifact@v4
with:
name: release-dll-pdb
path: out/build/x86-release-pdb/
name: relwithdebinfo-dll
path: out/build/x86-relwithdebinfo/
- name: Download Release DLL VDF
uses: actions/download-artifact@v4
with:
name: release-vdf-pdb
path: out/install/x86-release-pdb/
name: relwithdebinfo-vdf
path: out/install/x86-relwithdebinfo/
- name: Prepare Release Files
id: prepare-release
shell: powershell
Expand All @@ -63,9 +63,9 @@ jobs:
run: |
$tag = $env:GITHUB_REF -replace '^refs/tags/', ''
Compress-Archive out/install/x86-release/bin/* zBassMusic-${tag}.zip
Compress-Archive out/build/x86-release-pdb/* zBassMusic-${tag}-pdb.zip
Compress-Archive out/build/x86-relwithdebinfo/* zBassMusic-${tag}-relwithdebinfo.zip
Copy-Item out/install/x86-release/zBassMusic.vdf zBassMusic-${tag}.vdf
Copy-Item out/install/x86-release-pdb/zBassMusic.vdf zBassMusic-${tag}-pdb.vdf
Copy-Item out/install/x86-relwithdebinfo/zBassMusic.vdf zBassMusic-${tag}-relwithdebinfo.vdf
$prerelease = if (-not ($tag -match '^v?(\d+\.\d+\.\d+)$')) { 'true' } else { 'false' }
echo "prerelease=${prerelease}" >> $env:GITHUB_OUTPUT
- name: Release
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,5 @@ out
# Idea
.idea

!docs/**/release
!docs/**/release
.scannerwork
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@
url = https://gitlab.com/union-framework/union-api.git
[submodule ".\\dependencies\\union-api"]
url = https://gitlab.com/union-framework/union-api.git
[submodule "dependencies/gothic-api"]
path = dependencies/gothic-api
url = https://gitlab.com/union-framework/gothic-api
85 changes: 58 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.25..3.29.5)
set(PROJECT_VERSION "0.1.3")
set(PROJECT_VERSION_CMAKE "0.3.2")
project(zBassMusic VERSION ${PROJECT_VERSION_CMAKE})
set(VCPKG_TARGET_ARCHITECTURE "x86")
set(VCPKG_PLATFORM_TOOLSET "v143")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(zBassMusic VERSION "${PROJECT_VERSION_CMAKE}" LANGUAGES CXX)

option(BUILD_VDF "Build .VDF file with plugin" ON)
option(BUILD_TESTS "Build tests" ON)

set(UNION_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/union-api")
set(GOTHIC_API_DIR "${CMAKE_SOURCE_DIR}/dependencies/gothic-api")
set(BASS_DIR "${CMAKE_SOURCE_DIR}/dependencies/bass")
set(VDF_DIR "${CMAKE_SOURCE_DIR}/vdf")
set(GOTHIC_USERAPI_DIR "${CMAKE_SOURCE_DIR}/gothic-userapi")

set(CMAKE_CXX_STANDARD 23)
if (${CMAKE_BUILD_RELEASE_PDB})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAE_CXX_FLAGS_DEBUG} /Zc:__cplusplus")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAE_CXX_FLAGS_RELEASE} /Zc:__cplusplus")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAE_CXX_FLAGS_RELWITHDEBINFO} /Zc:__cplusplus")

include(FetchContent)
set(BUILD_UNION_API_STATIC OFF CACHE INTERNAL "Disable static build of UnionAPI")
FetchContent_Declare(
UnionAPI
URL https://github.com/piotrmacha/union-api.cmake/releases/latest/download/UnionAPI-v143-windows-2022.zip)
FetchContent_MakeAvailable(UnionAPI)
FetchContent_GetProperties(UnionAPI SOURCE_DIR UnionAPI_SOURCE_DIR)
set(CMAKE_FIND_PACKAGE_REDIRECTS_DIR ${UnionAPI_SOURCE_DIR})
set(UnionAPI_DIR ${UnionAPI_SOURCE_DIR}/lib/cmake/UnionAPI)
find_package(UnionAPI CONFIG REQUIRED)

include(cmake/union-api.cmake)
include(cmake/gothic-api.cmake)
find_package(spdlog CONFIG REQUIRED)
include(cmake/bass.cmake)

add_library(plugin SHARED)
set_target_properties(plugin PROPERTIES
add_library(zbassmusic SHARED)
set_target_properties(zbassmusic PROPERTIES
OUTPUT_NAME "zBassMusic"
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}")
Expand All @@ -35,16 +46,36 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in" "${CMAKE_CURRENT_BINA
configure_file("${CMAKE_SOURCE_DIR}/vdf/script.vdfs.in" "${CMAKE_BINARY_DIR}/script.vdfs")
configure_file("${CMAKE_SOURCE_DIR}/src/BuildInfo.h.in" "${CMAKE_BINARY_DIR}/src/BuildInfo.h" @ONLY)

file(GLOB_RECURSE PLUGIN_SOURCES "src/**.cpp" "${UNION_API_DIR}/union-api/Union/Memory.cpp")
target_sources(plugin PRIVATE ${PLUGIN_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/version.rc")
add_library(zbassmusic_gothicapi STATIC)
target_compile_options(zbassmusic_gothicapi PRIVATE /W1 /wd4530 /wd4005)
target_compile_definitions(zbassmusic_gothicapi PRIVATE __G1 __G1A __G2 __G2A)
target_link_libraries(zbassmusic_gothicapi PRIVATE UnionAPI::GothicAPI)

file(GLOB_RECURSE ZBASSMUSIC_SOURCES "src/**.cpp")
target_sources(zbassmusic PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/version.rc" ${ZBASSMUSIC_SOURCES})
target_compile_options(zbassmusic PRIVATE /W4 /WX /wd4530 /wd4005)
target_compile_definitions(zbassmusic PRIVATE __G1 __G1A __G2 __G2A)
target_include_directories(zbassmusic PRIVATE "src/" "${CMAKE_BINARY_DIR}/src/" "gothic-userapi"
"${CMAKE_BINARY_DIR}/_deps/unionapi-src/include"
"${CMAKE_BINARY_DIR}/_deps/unionapi-src/include/ZenGin/Gothic_UserAPI")
target_link_libraries(zbassmusic PRIVATE UnionAPI::UnionAPI zbassmusic_gothicapi bass_all)

add_compile_options(plugin PRIVATE /W4 /WX)
target_compile_definitions(plugin PRIVATE _UNION_API_DLL __G1 __G1A __G2 __G2A)
target_include_directories(plugin PRIVATE "src/" "${CMAKE_BINARY_DIR}/src/")
target_link_libraries(plugin PRIVATE union-api gothic-api bass_all)
if (${BUILD_TESTS})
enable_testing()
add_subdirectory(tests)
endif ()

install(FILES $<TARGET_RUNTIME_DLLS:zbassmusic> DESTINATION ${CMAKE_BINARY_DIR})
install(FILES $<TARGET_RUNTIME_DLLS:zbassmusic> TYPE BIN)
install(TARGETS zbassmusic
EXPORT zBassMusicTargets
LIBRARY DESTINATION bin
ARCHIVE DESTINATION bin
RUNTIME DESTINATION bin)
install(EXPORT zBassMusicTargets
FILE zBassMusicTargets.cmake
DESTINATION lib/cmake/Plugin)

install(FILES $<TARGET_RUNTIME_DLLS:plugin> "${CMAKE_BINARY_DIR}/zBassMusic.dll" TYPE BIN)
install(FILES $<TARGET_RUNTIME_DLLS:plugin> "${CMAKE_BINARY_DIR}/UnionAPI.dll" TYPE BIN)
if (${BUILD_VDF})
install(FILES "${CMAKE_BINARY_DIR}/script.vdfs" DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(SCRIPT "${VDF_DIR}/vdf.cmake")
Expand All @@ -54,16 +85,16 @@ endif ()

if (${BUILD_VDF})
string(REPLACE "build" "install" INSTALL_DIR "${CMAKE_BINARY_DIR}")
add_custom_target(plugin_vdf ALL
add_custom_target(zbassmusic_vdf ALL
COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR} --prefix ${INSTALL_DIR}
DEPENDS plugin
DEPENDS zbassmusic
COMMENT "Run install to build VDF")

if (DEFINED ENV{COPY_VDF_TARGET})
add_custom_target(copy_vdf ALL
COMMAND ${CMAKE_COMMAND} -E copy "${INSTALL_DIR}/zBassMusic.vdf" "$ENV{COPY_VDF_TARGET}"
DEPENDS plugin_vdf
COMMENT "Copy plugin to target directory: $ENV{COPY_VDF_TARGET}")
DEPENDS zbassmusic_vdf
COMMENT "Copy zbassmusic to target directory: $ENV{COPY_VDF_TARGET}")
endif ()
endif ()

Expand All @@ -75,6 +106,6 @@ if (DEFINED ENV{COPY_DLL_TARGET})
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassmidi.dll" "$ENV{COPY_DLL_TARGET}/bassmidi.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassopus.dll" "$ENV{COPY_DLL_TARGET}/bassopus.dll"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/dependencies/bass/lib/bassflac.dll" "$ENV{COPY_DLL_TARGET}/bassflac.dll"
DEPENDS plugin
COMMENT "Copy plugin to target directory: $ENV{COPY_DLL_TARGET}")
endif ()
DEPENDS zbassmusic
COMMENT "Copy zbassmusic to target directory: $ENV{COPY_DLL_TARGET}")
endif ()
Loading