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

CI: Add support for unity builds (#138) #139

Merged
merged 8 commits into from
Mar 1, 2025
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
7 changes: 6 additions & 1 deletion .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,20 @@ jobs:
{os: ubuntu-latest, dist: cp310-manylinux_x86_64},
{os: ubuntu-latest, dist: cp311-manylinux_x86_64},
{os: ubuntu-latest, dist: cp312-manylinux_x86_64},
{os: ubuntu-latest, dist: cp313-manylinux_x86_64},

{os: windows-latest, dist: cp37-win_amd64},
{os: windows-latest, dist: cp38-win_amd64},
{os: windows-latest, dist: cp39-win_amd64},
{os: windows-latest, dist: cp310-win_amd64},
{os: windows-latest, dist: cp311-win_amd64},
{os: windows-latest, dist: cp312-win_amd64},
{os: windows-latest, dist: cp313-win_amd64},

{os: macos-latest, dist: cp310-macosx_arm64},
{os: macos-latest, dist: cp311-macosx_arm64},
{os: macos-latest, dist: cp312-macosx_arm64}
{os: macos-latest, dist: cp312-macosx_arm64},
{os: macos-latest, dist: cp313-macosx_arm64}
]

steps:
Expand Down Expand Up @@ -113,6 +116,8 @@ jobs:
name: PhotoshopAPI_Py-${{ matrix.os_dist.os }}-${{ matrix.os_dist.dist }}
path: wheelhouse/*.whl

# Step to check if we can fetch the artifacts and they all come as expected, primarily a debugging
# sanity step
mock-publish:
name: Mock Upload release to PyPI
permissions:
Expand Down
32 changes: 18 additions & 14 deletions .github/workflows/cmake-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,22 @@ jobs:
os: ubuntu-24.04
compiler: gcc-13
compilercxx: g++-13
cflags: ""
cxxflags: ""
multiline-separator: \
- name: Ubuntu Clang
os: ubuntu-24.04
compiler: clang
compilercxx: clang++
cflags: ""
cxxflags: ""
multiline-separator: \
- name: Windows MSVC
os: windows-latest
compiler: msvc
compilercxx: msvc
cflags: ""
cxxflags: ""
multiline-separator: "`"
- name: MacOS ARM GCC
os: macos-latest
compiler: gcc-13
compilercxx: g++-13
cflags: ""
cxxflags: ""
multiline-separator: \

steps:
- uses: actions/checkout@v4
Expand All @@ -71,18 +67,26 @@ jobs:
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.compilercxx }}
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPSAPI_BUILD_DOCS=OFF -DPSAPI_BUILD_BENCHMARKS=OFF -DPSAPI_BUILD_TESTS=OFF -DPSAPI_BUILD_EXAMPLES=ON -DPSAPI_BUILD_PYTHON=OFF
cmake -B ${{github.workspace}}/build ${{ matrix.multiline-separator}}
-DCMAKE_UNITY_BUILD=ON ${{ matrix.multiline-separator}}
-DCMAKE_UNITY_BUILD_BATCH_SIZE=32 ${{ matrix.multiline-separator}}
-DCMAKE_OSX_ARCHITECTURES="arm64" ${{ matrix.multiline-separator}}
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_DOCS=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_BENCHMARKS=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_TESTS=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_EXAMPLES=ON ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_PYTHON=OFF


- name: Build ${{ matrix.os }}-${{ matrix.compilercxx }}
# Build your program with the given configuration
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.compilercxx }}
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)
run: |
cmake --build ${{github.workspace}}/build ${{ matrix.multiline-separator}}
--config ${{env.BUILD_TYPE}} ${{ matrix.multiline-separator}}
--parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)

18 changes: 16 additions & 2 deletions .github/workflows/cmake-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,28 @@ jobs:
compilercxx: g++-13
cflags: "-fsanitize=address,leak,undefined"
cxxflags: "-fsanitize=address,leak,undefined"
multiline-separator: \
- name: Ubuntu Clang
os: ubuntu-24.04
compiler: clang
compilercxx: clang++
cflags: "-fsanitize=address,leak,undefined"
cxxflags: "-fsanitize=address,leak,undefined"
multiline-separator: \
- name: Windows MSVC
os: windows-latest
compiler: msvc
compilercxx: msvc
cflags: ""
cxxflags: ""
multiline-separator: "`"
- name: MacOS ARM GCC
os: macos-latest
compiler: gcc-13
compilercxx: g++-13
cflags: ""
cxxflags: ""
multiline-separator: \

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -74,15 +78,25 @@ jobs:
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPSAPI_BUILD_DOCS=OFF -DPSAPI_BUILD_BENCHMARKS=OFF -DPSAPI_BUILD_EXAMPLES=OFF -DPSAPI_BUILD_PYTHON=OFF
cmake -B ${{github.workspace}}/build ${{ matrix.multiline-separator}}
-DCMAKE_UNITY_BUILD=ON ${{ matrix.multiline-separator}}
-DCMAKE_OSX_ARCHITECTURES="arm64" ${{ matrix.multiline-separator}}
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_DOCS=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_BENCHMARKS=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_EXAMPLES=OFF ${{ matrix.multiline-separator}}
-DPSAPI_BUILD_PYTHON=OFF ${{ matrix.multiline-separator}}

- name: Build ${{ matrix.os }}-${{ matrix.compilercxx }}
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.compilercxx }}
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)
run: |
cmake --build ${{github.workspace}}/build ${{ matrix.multiline-separator}}
--config ${{env.BUILD_TYPE}} ${{ matrix.multiline-separator}}
--parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)

# On windows we need to copy the test files differently as it generates sub-folders
# for the copied test files
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/cmake-valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ jobs:
os: ubuntu-24.04
compiler: gcc-13
compilercxx: g++-13
cflags: ""
cxxflags: ""
- name: Ubuntu Clang
os: ubuntu-24.04
compiler: clang
compilercxx: clang++
cflags: ""
cxxflags: ""

steps:
- uses: actions/checkout@v4
Expand All @@ -53,15 +49,24 @@ jobs:
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: |
cmake -B ${{github.workspace}}/build -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DPSAPI_BUILD_DOCS=OFF -DPSAPI_BUILD_BENCHMARKS=OFF -DPSAPI_BUILD_EXAMPLES=ON -DPSAPI_BUILD_PYTHON=OFF
cmake -B ${{github.workspace}}/build \
-DCMAKE_UNITY_BUILD=ON \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DPSAPI_BUILD_DOCS=OFF \
-DPSAPI_BUILD_BENCHMARKS=OFF \
-DPSAPI_BUILD_EXAMPLES=ON \
-DPSAPI_BUILD_PYTHON=OFF

- name: Build ${{ matrix.os }}-${{ matrix.compilercxx }}
env:
CC: ${{ matrix.compiler }}
CXX: ${{ matrix.compilercxx }}
CFLAGS: ${{ matrix.cflags }}
CXXFLAGS: ${{ matrix.cxxflags }}
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)
run: |
cmake --build ${{github.workspace}}/build \
--config ${{env.BUILD_TYPE}} \
--parallel $(getconf _NPROCESSORS_ONLN || sysctl -n hw.ncpu || echo %NUMBER_OF_PROCESSORS%)

- name: Run Valgrind
if: matrix.os == 'ubuntu-24.04'
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ set(BUILD_FUZZERS OFF)
set(BUILD_BENCHMARKS OFF)
set(BUILD_EXAMPLES OFF)
add_subdirectory (thirdparty/c-blosc2 EXCLUDE_FROM_ALL)
# In our CI we use unity builds to speed up compilation but due to c-blosc2's build
# setup this doesn't work and will result in undefined references
if (CMAKE_UNITY_BUILD)
set_target_properties(blosc2_static PROPERTIES UNITY_BUILD OFF)
set_target_properties(blosc2_shared PROPERTIES UNITY_BUILD OFF)
endif()

# Add target for blosc2 headers
add_library(blosc2_include INTERFACE)
Expand Down Expand Up @@ -102,6 +108,9 @@ if(PSAPI_BUILD_STATIC)
endif()
if(PSAPI_BUILD_TESTS)
add_subdirectory (PhotoshopTest)
if (CMAKE_UNITY_BUILD)
set_target_properties(PhotoshopTest PROPERTIES UNITY_BUILD OFF)
endif()
endif()
if(PSAPI_BUILD_BENCHMARKS)
add_subdirectory (PhotoshopBenchmark)
Expand Down
15 changes: 14 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def build_extension(self, ext: CMakeExtension) -> None:
# In this example, we pass in the version to C++. You might not need to.
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"]

# Enable unity builds for speed ups
cmake_args += ["-DCMAKE_UNITY_BUILD=ON"]
cmake_args += ["-DCMAKE_UNITY_BUILD_BATCH_SIZE=16"]

if self.compiler.compiler_type != "msvc":
# Using Ninja-build since it a) is available as a wheel and b)
# multithreads automatically. MSVC would require all variables be
Expand Down Expand Up @@ -142,7 +146,16 @@ def build_extension(self, ext: CMakeExtension) -> None:
build_temp.mkdir(parents=True)

subprocess.run(
["cmake", ext.sourcedir, *cmake_args, "-DPSAPI_BUILD_PYTHON=ON","-DPSAPI_BUILD_DOCS=OFF", "-DPSAPI_BUILD_BENCHMARKS=OFF", "-DPSAPI_BUILD_EXAMPLES=OFF", "-DPSAPI_BUILD_TESTS=OFF"], cwd=build_temp, check=True
[
"cmake",
ext.sourcedir,
*cmake_args,
"-DPSAPI_BUILD_PYTHON=ON",
"-DPSAPI_BUILD_DOCS=OFF",
"-DPSAPI_BUILD_BENCHMARKS=OFF",
"-DPSAPI_BUILD_EXAMPLES=OFF",
"-DPSAPI_BUILD_TESTS=OFF"
], cwd=build_temp, check=True
)
subprocess.run(
["cmake", "--build", ".", *build_args], cwd=build_temp, check=True
Expand Down
Loading