summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCassandra Beckley <cbeckley@google.com>2023-01-31 10:03:03 -0800
committerGitHub <noreply@github.com>2023-01-31 19:03:03 +0100
commitabd85955cb0af1fc95dc5dc545ce42cdb088c020 (patch)
tree58963eb52482f9ad29092c10e2f3eab5dde8be77
parent902836893df44ac2b9db154b9514b2245f4111ce (diff)
downloadSPIRV-Reflect-abd85955cb0af1fc95dc5dc545ce42cdb088c020.tar.gz
Add GitHub actions to check formatting and run tests (#165)
* Add GitHub actions to check formatting and run tests Based on the workflows from google/bigwheels * Fix PR comments * Fix typos and build commands * Try to fix macOS build * Try to fix Windows Bazel build * Try to handle fallthrough on macOS * Try to fix linker options * Disable Windows tests for now
-rw-r--r--.github/workflows/bazel-build.yml28
-rw-r--r--.github/workflows/check-formatting.yml47
-rw-r--r--.github/workflows/linux-cmake-build.yml33
-rw-r--r--.github/workflows/windows-cmake-build.yml30
-rw-r--r--BUILD.bazel35
-rw-r--r--spirv_reflect.c8
6 files changed, 174 insertions, 7 deletions
diff --git a/.github/workflows/bazel-build.yml b/.github/workflows/bazel-build.yml
new file mode 100644
index 0000000..5156799
--- /dev/null
+++ b/.github/workflows/bazel-build.yml
@@ -0,0 +1,28 @@
+name: Bazel build
+
+on:
+ pull_request:
+
+permissions: read-all
+
+jobs:
+ bazel-build:
+ name: Build and run tests using Bazel
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest, windows-latest]
+ runs-on: ${{matrix.os}}
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: '0'
+ - name: Clone submodules
+ run: git submodule update --init --recursive
+ - name: Mount Bazel cache
+ uses: actions/cache@v3
+ with:
+ path: ~/.bazel/cache
+ key: bazel-cache-${{ runner.os }}
+ - name: Build
+ run: bazel --output_user_root=~/.bazel/cache build :all
diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml
new file mode 100644
index 0000000..bc6d243
--- /dev/null
+++ b/.github/workflows/check-formatting.yml
@@ -0,0 +1,47 @@
+name: Code formatting check
+
+on:
+ pull_request:
+
+# Cancel previous runs if a more recent commit is pushed.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.head_ref }}
+ cancel-in-progress: true
+
+permissions: read-all
+
+jobs:
+ clang-format-check:
+ name: clang-format
+ runs-on: "ubuntu-20.04"
+ steps:
+ - name: Setup clang-format
+ run: |
+ sudo apt-get install -yqq clang-format-12
+ - name: Checkout repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: '0'
+ - name: Switch to pull request branch
+ run: |
+ git checkout ${GITHUB_SHA}
+ - name: Run clang-format
+ run: |
+ git diff origin/${{ github.base_ref }} -U0 --no-color -- '**/*.cpp' '**/*.cc' '**/*.h' '**/*.hh' '**/*.hpp' \
+ | clang-format-diff-12 -p1 >not-formatted.diff 2>&1
+ - name: Check formatting
+ run: |
+ if ! grep -q '[^[:space:]]' not-formatted.diff ; then
+ echo "Code is formatted."
+ else
+ echo "Code is not formatted."
+ echo "Run clang-format-diff on your changes:"
+ echo " git diff origin/${{ github.base_ref }} -U0 --no-color | clang-format-diff -p1 -i"
+ echo ""
+ echo "You can disable clang-format for specific code blocks. Follow https://clang.llvm.org/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code."
+ echo ""
+ echo "Diff:"
+ cat not-formatted.diff
+ echo ""
+ exit 3
+ fi
diff --git a/.github/workflows/linux-cmake-build.yml b/.github/workflows/linux-cmake-build.yml
new file mode 100644
index 0000000..3d128f6
--- /dev/null
+++ b/.github/workflows/linux-cmake-build.yml
@@ -0,0 +1,33 @@
+name: Linux build
+
+on:
+ pull_request:
+
+# Cancel previous runs if a more recent commit is pushed.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.head_ref }}
+ cancel-in-progress: true
+
+permissions: read-all
+
+jobs:
+ linux-build:
+ name: Build and run tests on Linux using CMake
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: '0'
+ - name: Clone submodules
+ run: git submodule update --init --recursive
+ - name: Build
+ run: |
+ mkdir build
+ cd build
+ cmake .. -DSPIRV_REFLECT_BUILD_TESTS=ON
+ make -j $(nproc)
+ - name: Run unit tests
+ run: |
+ cd build
+ ./test-spirv-reflect
diff --git a/.github/workflows/windows-cmake-build.yml b/.github/workflows/windows-cmake-build.yml
new file mode 100644
index 0000000..19df5dd
--- /dev/null
+++ b/.github/workflows/windows-cmake-build.yml
@@ -0,0 +1,30 @@
+name: Windows build
+
+on:
+ pull_request:
+
+# Cancel previous runs if a more recent commit is pushed.
+concurrency:
+ group: ${{ github.workflow }}-${{ github.head_ref }}
+ cancel-in-progress: true
+
+permissions: read-all
+
+jobs:
+ windows-build:
+ name: Build and run tests on Windows using CMake
+ runs-on: windows-latest
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: '0'
+ - name: Clone submodules
+ run: git submodule update --init --recursive
+ - name: Build
+ run: |
+ mkdir build
+ cd build
+ cmake -DSPIRV_REFLECT_BUILD_TESTS=ON ..
+
+ cmake --build . --config Release -- /nologo /verbosity:minimal /maxcpucount
diff --git a/BUILD.bazel b/BUILD.bazel
index 7ac7417..dd7c496 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -4,8 +4,7 @@ package(
# Description:
#
-# The Amber project provides an API and commands for testing shader
-# compiler stack.
+# SPIRV-Reflect is a lightweight library that provides a C/C++ reflection API for SPIR-V shader bytecode in Vulkan applications.
licenses(["notice"]) # Apache 2.0
@@ -14,7 +13,15 @@ exports_files([
"LICENSE",
])
-COMMON_COPTS = [
+COPTS_WINDOWS = [
+ "/Gy",
+ "/Gw",
+
+ "/W3",
+ "/WX",
+]
+
+COPTS_DEFAULT = [
"-ffunction-sections",
"-fdata-sections",
@@ -24,11 +31,25 @@ COMMON_COPTS = [
"-Wunused-variable",
]
-COMMON_CPPOPTS = COMMON_COPTS + [
- "-std=c++14",
-]
+COMMON_COPTS = select({
+ "@bazel_tools//src/conditions:windows": COPTS_WINDOWS,
+ "//conditions:default": COPTS_DEFAULT,
+})
+
+COMMON_CPPOPTS = select({
+ "@bazel_tools//src/conditions:windows": COPTS_WINDOWS + [
+ "/std:c++14"
+ ],
+ "//conditions:default": COPTS_DEFAULT + [
+ "-std=c++14",
+ ]
+})
-COMMON_LINKOPTS = ["-Wl,--gc-sections"]
+COMMON_LINKOPTS = select({
+ "@bazel_tools//src/conditions:darwin": ["-Wl,-dead_strip"],
+ "@bazel_tools//src/conditions:windows": ["/OPT:REF"],
+ "//conditions:default": ["-Wl,--gc-sections"],
+})
cc_library(
name = "libspirv_reflect",
diff --git a/spirv_reflect.c b/spirv_reflect.c
index 9e6976b..439d2f4 100644
--- a/spirv_reflect.c
+++ b/spirv_reflect.c
@@ -27,6 +27,12 @@
#include <stdlib.h>
#endif
+#if defined(__clang__)
+ #define FALLTHROUGH __attribute__((fallthrough))
+#else
+ #define FALLTHROUGH
+#endif
+
#if defined(SPIRV_REFLECT_ENABLE_ASSERTS)
#define SPV_REFLECT_ASSERT(COND) \
assert(COND);
@@ -753,6 +759,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser)
case SpvOpTypeStruct:
{
p_node->member_count = p_node->word_count - 2;
+ FALLTHROUGH;
} // Fall through
case SpvOpTypeVoid:
case SpvOpTypeBool:
@@ -919,6 +926,7 @@ static SpvReflectResult ParseNodes(SpvReflectPrvParser* p_parser)
CHECKED_READU32(p_parser, p_func_node->word_offset + 2, p_func_node->result_id);
++(p_parser->function_count);
}
+ FALLTHROUGH;
} // Fall through
case SpvOpFunctionEnd: