From 0321b5f0a708880af11e99b66e2329bbcfbb0648 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 13:22:25 +0700 Subject: [PATCH 1/6] replace language matrix in `use-action-with-specified-compiler` job with os matrix --- .github/workflows/test.yml | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4a4e33..9b66abe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,38 +40,28 @@ jobs: run: test ! -d build use-action-with-specified-compiler: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: - lang: [C, CXX] + os: [windows-latest, ubuntu-latest, macos-latest] steps: - name: Checkout repository uses: actions/checkout@v3.3.0 - - name: Use this action with specified invalid compiler - id: failed_step - continue-on-error: true - uses: ./ - with: - source-dir: test - c-compiler: ${{ matrix.lang == 'C' && 'invalid' || '' }} - cxx-compiler: ${{ matrix.lang == 'CXX' && 'invalid' || '' }} - - - name: Check if previous step is failing - run: ${{ steps.failed_step.outcome == 'failure' && 'true' || 'false' }} - - name: Use this action with specified compiler uses: ./ with: source-dir: test - c-compiler: ${{ matrix.lang == 'C' && 'clang' || '' }} - cxx-compiler: ${{ matrix.lang == 'CXX' && 'clang++' || '' }} + c-compiler: clang + cxx-compiler: clang++ args: | - -D BUILD_C=${{ matrix.lang == 'C' && 'ON' || 'OFF' }} - -D BUILD_CXX=${{ matrix.lang == 'CXX' && 'ON' || 'OFF' }} + -D BUILD_C=ON + -D BUILD_CXX=ON - name: Run build result - run: build/${{ matrix.lang == 'C' && 'hello_world_c' || 'hello_world' }} + run: | + {{ matrix.os == 'windows-latest' && 'build\Debug\hello_world.exe' || 'build/hello_world' }} + {{ matrix.os == 'windows-latest' && 'build\Debug\hello_world_c.exe' || 'build/hello_world_c' }} use-action-with-specified-generator: runs-on: ${{ matrix.os }} From 1615d1b12a9bfd4a99662b96ccaa5a5bcf8936ef Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 21:07:29 +0700 Subject: [PATCH 2/6] add option to check if using clang for `test_c` and `test_cpp` targets --- test/CMakeLists.txt | 5 +++++ test/test.c | 4 ++++ test/test.cpp | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 617b4f1..a166a0c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -4,6 +4,8 @@ project(test) option(BUILD_C "build hello world in C Language" OFF) option(BUILD_CXX "build hello world in CXX Language" ON) +option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) + if(BUILD_C) add_executable(hello_world_c hello_world.c) endif() @@ -13,4 +15,7 @@ if(BUILD_CXX) endif() add_executable(test_c EXCLUDE_FROM_ALL test.c) +target_compile_definitions(test_c PRIVATE $<$:CHECK_USING_CLANG>) + add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp) +target_compile_definitions(test_cpp PRIVATE $<$:CHECK_USING_CLANG>) diff --git a/test/test.c b/test/test.c index e9a0a23..325c6c7 100644 --- a/test/test.c +++ b/test/test.c @@ -1,6 +1,10 @@ #include int main() { +#if defined(CHECK_USING_CLANG) && !defined(__clang__) + printf("compiler is not clang\n"); + return 1; +#endif printf("all ok\n"); return 0; } diff --git a/test/test.cpp b/test/test.cpp index c36cbb6..b3c6941 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,6 +1,10 @@ #include int main() { +#if defined(CHECK_USING_CLANG) && !defined(__clang__) + std::cout << "compiler is not clang" << std::endl; + return 1; +#endif std::cout << "all ok" << std::endl; return 0; } From 07b809b1eb58d49bfa2153eaf6c1df0f9d9c1740 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 21:57:08 +0700 Subject: [PATCH 3/6] use `test_c` and `test_cpp` with check for using clang in the use action with specified compiler job --- .github/workflows/test.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6ede197..5499ec1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,16 +67,15 @@ jobs: uses: ./ with: source-dir: test + targets: test_c test_cpp c-compiler: clang cxx-compiler: clang++ - args: | - -D BUILD_C=ON - -D BUILD_CXX=ON + args: -D CHECK_USING_CLANG=ON - name: Run build result run: | - {{ matrix.os == 'windows-latest' && 'build\Debug\hello_world.exe' || 'build/hello_world' }} - {{ matrix.os == 'windows-latest' && 'build\Debug\hello_world_c.exe' || 'build/hello_world_c' }} + ${{ matrix.os == 'windows-latest' && 'build\Debug\test_c.exe' || 'build/test_c' }} + ${{ matrix.os == 'windows-latest' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }} use-action-with-specified-generator: runs-on: ${{ matrix.os }} From 965ce1d4a85e65ae24fd23d1d169234891158c77 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 12 Jan 2023 14:03:53 +0700 Subject: [PATCH 4/6] test using clang with ninja --- .github/workflows/test.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5499ec1..efc58fd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -68,14 +68,13 @@ jobs: with: source-dir: test targets: test_c test_cpp + generator: Ninja c-compiler: clang cxx-compiler: clang++ args: -D CHECK_USING_CLANG=ON - name: Run build result - run: | - ${{ matrix.os == 'windows-latest' && 'build\Debug\test_c.exe' || 'build/test_c' }} - ${{ matrix.os == 'windows-latest' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }} + run: build/test_c && build/test_cpp use-action-with-specified-generator: runs-on: ${{ matrix.os }} From 0971b49fe1bb06b9f71a6ef92b7f55f14b8d0745 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 12 Jan 2023 14:16:22 +0700 Subject: [PATCH 5/6] remove `BUILD_C` and `BUILD_CXX` option in the test project --- test/CMakeLists.txt | 11 +---------- test/hello_world.c | 6 ------ 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 test/hello_world.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a166a0c..04d05be 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,18 +1,9 @@ cmake_minimum_required(VERSION 3.0) project(test) -option(BUILD_C "build hello world in C Language" OFF) -option(BUILD_CXX "build hello world in CXX Language" ON) - option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) -if(BUILD_C) - add_executable(hello_world_c hello_world.c) -endif() - -if(BUILD_CXX) - add_executable(hello_world hello_world.cpp) -endif() +add_executable(hello_world hello_world.cpp) add_executable(test_c EXCLUDE_FROM_ALL test.c) target_compile_definitions(test_c PRIVATE $<$:CHECK_USING_CLANG>) diff --git a/test/hello_world.c b/test/hello_world.c deleted file mode 100644 index 7791fbb..0000000 --- a/test/hello_world.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - printf("Hello world!\n"); - return 0; -} From ab9af67ec96cfed39805714ed521f7b774999c04 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 12 Jan 2023 14:32:06 +0700 Subject: [PATCH 6/6] merge file and configuration for `test_c` and `test_cpp` --- test/CMakeLists.txt | 15 ++++++++++----- test/test.c | 10 ---------- test/test.cpp | 10 ---------- test/test.in | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 25 deletions(-) delete mode 100644 test/test.c delete mode 100644 test/test.cpp create mode 100644 test/test.in diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04d05be..1e108b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,8 +5,13 @@ option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) add_executable(hello_world hello_world.cpp) -add_executable(test_c EXCLUDE_FROM_ALL test.c) -target_compile_definitions(test_c PRIVATE $<$:CHECK_USING_CLANG>) - -add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp) -target_compile_definitions(test_cpp PRIVATE $<$:CHECK_USING_CLANG>) +list(APPEND LANGS c cpp) +foreach(LANG ${LANGS}) + configure_file(test.in ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG}) + add_executable(test_${LANG} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_BINARY_DIR}/test.${LANG}) + target_compile_definitions( + test_${LANG} PRIVATE + $<$:IS_C> + $<$:CHECK_USING_CLANG> + ) +endforeach() diff --git a/test/test.c b/test/test.c deleted file mode 100644 index 325c6c7..0000000 --- a/test/test.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main() { -#if defined(CHECK_USING_CLANG) && !defined(__clang__) - printf("compiler is not clang\n"); - return 1; -#endif - printf("all ok\n"); - return 0; -} diff --git a/test/test.cpp b/test/test.cpp deleted file mode 100644 index b3c6941..0000000 --- a/test/test.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main() { -#if defined(CHECK_USING_CLANG) && !defined(__clang__) - std::cout << "compiler is not clang" << std::endl; - return 1; -#endif - std::cout << "all ok" << std::endl; - return 0; -} diff --git a/test/test.in b/test/test.in new file mode 100644 index 0000000..6a4eb5f --- /dev/null +++ b/test/test.in @@ -0,0 +1,16 @@ +#ifdef IS_C +#include +#define PRINT(STR) printf(STR); printf("\n") +#else +#include +#define PRINT(STR) std::cout << STR << std::endl +#endif + +int main() { +#if defined(CHECK_USING_CLANG) && !defined(__clang__) + PRINT("compiler is not clang"); + return 1; +#endif + PRINT("all ok"); + return 0; +}