Skip to content
Merged
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
192 changes: 192 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
name: Cross-Platform Release Build

on:
push:
tags:
- 'v*'

env:
BUILD_TYPE: Release

jobs:
build:
name: Build ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.os }}
strategy:
matrix:
platform:
- name: linux-x64
os: ubuntu-latest
arch: x64
cmake_args: ""
artifact_name: ulog-linux-x64
build_examples: "ON"
build_tools: "ON"
- name: linux-arm64
os: ubuntu-latest
arch: arm64
cmake_args: "-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++"
artifact_name: ulog-linux-arm64
build_examples: "OFF"
build_tools: "ON"
- name: linux-arm32
os: ubuntu-latest
arch: arm32
cmake_args: "-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=arm -DCMAKE_C_COMPILER=arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabihf-g++"
artifact_name: ulog-linux-arm32
build_examples: "OFF"
build_tools: "ON"

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install cross-compilation toolchains (ARM64)
if: matrix.platform.arch == 'arm64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

- name: Install cross-compilation toolchains (ARM32)
if: matrix.platform.arch == 'arm32'
run: |
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf

- name: Configure CMake
run: |
cmake -B ${{github.workspace}}/build \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DULOG_BUILD_EXAMPLES=${{ matrix.platform.build_examples }} \
-DULOG_BUILD_TOOLS=${{ matrix.platform.build_tools }} \
-DULOG_BUILD_TESTS=OFF \
${{ matrix.platform.cmake_args }}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j$(nproc)

- name: Install to staging area
run: |
mkdir -p ${{github.workspace}}/package
cmake --install ${{github.workspace}}/build --prefix ${{github.workspace}}/package

- name: Copy binaries and examples
run: |
# Copy main library
cp ${{github.workspace}}/build/libulog.a ${{github.workspace}}/package/

# Copy examples if they exist
if [ -f "${{github.workspace}}/build/examples/ulog_example_asyn" ]; then
mkdir -p ${{github.workspace}}/package/examples
cp ${{github.workspace}}/build/examples/ulog_example_* ${{github.workspace}}/package/examples/ || true
fi

# Copy tools if they exist
if [ -f "${{github.workspace}}/build/tools/logroller/logroller" ]; then
mkdir -p ${{github.workspace}}/package/tools
cp ${{github.workspace}}/build/tools/logroller/logroller ${{github.workspace}}/package/tools/
fi

- name: Create README for package
run: |
cat > ${{github.workspace}}/package/README.txt << EOF
ulog Library Package
===================
Platform: ${{ matrix.platform.name }}
Architecture: ${{ matrix.platform.arch }}
Build Type: ${{env.BUILD_TYPE}}
Git Tag: ${{ github.ref_name }}

Contents:
- lib/libulog.a - Main ulog static library
- include/ulog/ - Header files
- examples/ - Example programs (if built)
- tools/ - Tools like logroller (if built)

Usage:
Include the header files in your project and link against libulog.a

Example compilation:
gcc -I./include your_program.c -L. -lulog -o your_program

For more information, visit: https://github.com/ShawnFeng0/ulog
EOF

- name: Create package archive
run: |
cd ${{github.workspace}}/package
tar -czf ../${{ matrix.platform.artifact_name }}-${{ github.ref_name }}.tar.gz *

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.artifact_name }}-${{ github.ref_name }}
path: ${{github.workspace}}/${{ matrix.platform.artifact_name }}-${{ github.ref_name }}.tar.gz
retention-days: 30

release:
name: Create Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
permissions:
contents: write

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts

- name: Display structure of downloaded files
run: ls -la ./artifacts/

- name: Create release body
run: |
cat > release_body.md << 'EOF'
## Cross-Platform Release for ${{ github.ref_name }}

This release includes pre-built binaries for multiple architectures:

### Platforms:
- **linux-x64**: Native x86_64 Linux build
- **linux-arm64**: ARM64/AArch64 Linux build (cross-compiled)
- **linux-arm32**: ARM32 Linux build (cross-compiled)

### Contents:
Each package contains:
- Static library (`libulog.a`)
- Header files for development
- Example programs
- Tools (logroller)
- Documentation

### Usage:
1. Download the appropriate package for your target platform
2. Extract the archive
3. Include the headers and link against the static library
4. See README.txt in each package for detailed instructions

**Note**: ARM builds are cross-compiled and may require appropriate runtime libraries on target systems.
EOF

- name: Create Release and Upload Assets
run: |
# Create release
gh release create ${{ github.ref_name }} \
--title "Release ${{ github.ref_name }}" \
--notes-file release_body.md

# Upload all artifacts
for artifact_dir in ./artifacts/*/; do
artifact_file=$(find "$artifact_dir" -name "*.tar.gz" | head -1)
if [ -f "$artifact_file" ]; then
echo "Uploading $artifact_file"
gh release upload ${{ github.ref_name }} "$artifact_file"
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -540,3 +540,4 @@ MigrationBackup/

# vscode cmake build
build
build-*
74 changes: 74 additions & 0 deletions CROSS_PLATFORM_BUILDS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Cross-Platform Release Build Workflow

This repository includes an automated workflow that builds cross-platform packages whenever a new tag is created.

## Supported Platforms

The workflow automatically builds packages for the following architectures:

- **linux-x64**: Native x86_64 Linux build (includes examples and tools)
- **linux-arm64**: ARM64/AArch64 Linux build (cross-compiled, includes tools)
- **linux-arm32**: ARM32 Linux build (cross-compiled, includes tools)

## How to Trigger a Release

1. Create a new git tag:
```bash
git tag v1.0.0
git push origin v1.0.0
```

2. The workflow will automatically:
- Build the library for all supported architectures
- Package each build with headers and documentation
- Create a GitHub release with all packages attached

## Package Contents

Each package contains:
- `lib/libulog.a` - Static library for the target architecture
- `include/ulog/` - Header files for development
- `tools/` - Tools like logroller for all platforms
- `README.txt` - Platform-specific usage instructions

For the x64 build only:
- `examples/` - Example programs

## Usage

1. Download the appropriate package for your target platform from the releases page
2. Extract the archive
3. Include the headers in your project: `-I./include`
4. Link against the static library: `-L./lib -lulog`

Example compilation:
```bash
gcc -I./include your_program.c -L./lib -lulog -o your_program
```

## Cross-Compilation Notes

- ARM builds are cross-compiled on Ubuntu using standard cross-compilation toolchains
- ARM packages now include the logroller tool for all platforms
- For ARM targets, you may need appropriate runtime libraries on the target system
- Examples are only included in the x64 build to avoid potential compatibility issues

## Workflow Details

The workflow is defined in `.github/workflows/release.yml` and:
- Triggers on any tag push matching `v*`
- Uses Ubuntu runners with cross-compilation toolchains
- Builds in Release mode with optimizations
- Creates compressed archives for each platform
- Uploads all packages to a single GitHub release

## Troubleshooting

If you encounter issues with the packages:

1. **ARM libraries not working**: Ensure you have the correct runtime libraries installed on your target system
2. **Linking errors**: Make sure you're using the correct architecture package for your target
3. **Missing examples**: Examples are only available in the x64 package - use those for reference
4. **Tools not working on ARM**: Ensure you have the necessary shared libraries (like libzstd) on your ARM target system

For issues with the workflow itself, check the Actions tab in the GitHub repository.
Loading