Skip to content

Commit

Permalink
Add build and package github workflow (#1)
Browse files Browse the repository at this point in the history
PGZXB authored Jul 31, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 805c863 commit 7a33c87
Showing 2 changed files with 129 additions and 5 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/build-and-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build and Package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
device_info: "windows-x86_64"
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
device_info: "linux-x86_64"
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
device_info: "linux-x86_64"
- os: macOS-latest
c_compiler: clang
cpp_compiler: clang++
device_info: "darwin-x86_64"
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
- os: macOS-latest
c_compiler: gcc
- os: macOS-latest
c_compiler: cl

steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'

- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt update && sudo apt install -y libwayland-dev libxkbcommon-dev xorg-dev
shell: bash

- name: Set reusable strings
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
echo "built-package-name=imgui4cj-${{ github.sha }}-${{ matrix.device_info }}" >> "$GITHUB_OUTPUT"
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}

- name: Copy built library to src/libs (Windows)
if: matrix.os == 'windows-latest'
run: |
Copy-Item "${{ steps.strings.outputs.build-output-dir }}\Release\imgui4cj_c_lib.dll" -Destination "${{ github.workspace }}\src\libs\imgui4cj_c_lib.dll"
Copy-Item "${{ steps.strings.outputs.build-output-dir }}\Release\imgui4cj_c_lib.dll" -Destination "${{ github.workspace }}\src\libs\libimgui4cj_c_lib.dll"
shell: powershell

- name: Copy built library to src/libs (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
cp ${{ steps.strings.outputs.build-output-dir }}/imgui4cj_c_lib.so ${{ github.workspace }}/src/libs/imgui4cj_c_lib.so
cp ${{ steps.strings.outputs.build-output-dir }}/imgui4cj_c_lib.so ${{ github.workspace }}/src/libs/libimgui4cj_c_lib.so
shell: bash

- name: Copy built library to src/libs (MacOS)
if: matrix.os == 'macOS-latest'
run: |
cp ${{ steps.strings.outputs.build-output-dir }}/imgui4cj_c_lib.dylib ${{ github.workspace }}/src/libs/imgui4cj_c_lib.dylib
cp ${{ steps.strings.outputs.build-output-dir }}/imgui4cj_c_lib.dylib ${{ github.workspace }}/src/libs/libimgui4cj_c_lib.dylib
shell: bash

- name: Package files (Windows)
if: matrix.os == 'windows-latest'
run: |
New-Item -Path . -Name ${{ steps.strings.outputs.built-package-name }} -ItemType Directory
Copy-Item -Path cjpm.toml -Destination ${{ steps.strings.outputs.built-package-name }}\
Copy-Item -Path src -Destination ${{ steps.strings.outputs.built-package-name }}\ -Recurse
Compress-Archive -Path ${{ steps.strings.outputs.built-package-name }} -DestinationPath ${{ steps.strings.outputs.built-package-name }}.zip
shell: powershell

- name: Package files (Ubuntu, MacOS)
if: matrix.os != 'windows-latest'
run: |
mkdir -p ${{ steps.strings.outputs.built-package-name }}
cp cjpm.toml ${{ steps.strings.outputs.built-package-name }}/
cp -r src ${{ steps.strings.outputs.built-package-name }}/
tar -czvf ${{ steps.strings.outputs.built-package-name }}.tar.gz ${{ steps.strings.outputs.built-package-name }}/
shell: bash

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
${{ steps.strings.outputs.built-package-name }}.zip
${{ steps.strings.outputs.built-package-name }}.tar.gz
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -44,11 +44,13 @@ if(IMGUI4CJ_GLFW_OPENGL3_BACKEND)

# OpenGL3
list(APPEND IMGUI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/external/cimgui/imgui/backends/imgui_impl_opengl3.cpp)
if (WIN32) # Windows
list(APPEND IMGUI_LIBRARIES opengl32)
else (WIN32) # Unix
list(APPEND IMGUI_LIBRARIES GL)
endif (WIN32)

find_package(OpenGL REQUIRED)
if (OPENGL_FOUND)
list(APPEND IMGUI_LIBRARIES ${OPENGL_gl_LIBRARY})
else (OPENGL_FOUND)
message(FATAL_ERROR "OpenGL not found")
endif()

# GLFW
list(APPEND IMGUI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/external/cimgui/imgui/backends/imgui_impl_glfw.cpp)

0 comments on commit 7a33c87

Please sign in to comment.