From aecf9bb8cc660d6fc4e02b30e67040dd76b624ef Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Thu, 22 Jan 2026 16:35:49 +0800 Subject: [PATCH] chore: fix github action build issue --- .github/linux_build.sh | 3 +++ .github/macos_build.sh | 3 +++ .github/workflows/linux.yml | 10 ++++++++-- .github/workflows/macos.yml | 9 +++++++-- .github/workflows/windows.yml | 29 ++++++++++++++++++++--------- src/yycc/env.cpp | 9 +++++---- test/yycc/windows/console.cpp | 5 +++-- 7 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.github/linux_build.sh b/.github/linux_build.sh index 7e6e571..09562bd 100644 --- a/.github/linux_build.sh +++ b/.github/linux_build.sh @@ -1,6 +1,9 @@ #!/bin/bash set -euo pipefail +GTest_ROOT="${GTest_ROOT:?GTest_ROOT must be set}" +benchmark_ROOT="${benchmark_ROOT:?benchmark_ROOT must be set}" + # Create build directory and enter it mkdir bin cd bin diff --git a/.github/macos_build.sh b/.github/macos_build.sh index 7e6e571..09562bd 100644 --- a/.github/macos_build.sh +++ b/.github/macos_build.sh @@ -1,6 +1,9 @@ #!/bin/bash set -euo pipefail +GTest_ROOT="${GTest_ROOT:?GTest_ROOT must be set}" +benchmark_ROOT="${benchmark_ROOT:?benchmark_ROOT must be set}" + # Create build directory and enter it mkdir bin cd bin diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 1356296..fc2d2ab 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -10,6 +10,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - name: Install Dependencies + shell: bash run: | sudo apt update sudo apt install -y build-essential cmake git @@ -20,6 +21,7 @@ jobs: ref: 'v1.17.0' path: 'extern/googletest' - name: Build Google Test + shell: bash run: | # Build Google Test cd extern/googletest @@ -30,7 +32,7 @@ jobs: cmake --install . --prefix=../install cd .. cd install - export GTest_ROOT=$(pwd) + echo "GTest_ROOT=$(pwd)" >> "$GITHUB_ENV" cd ../.. - name: Fetch Google Benchmark uses: actions/checkout@v4 @@ -39,6 +41,7 @@ jobs: ref: 'v1.9.4' path: 'extern/benchmark' - name: Build Google Benchmark + shell: bash run: | # Build Google Benchmark cd extern/benchmark @@ -51,16 +54,19 @@ jobs: cmake --install . --prefix=../install cd .. cd install - export benchmark_ROOT=$(pwd) + echo "benchmark_ROOT=$(pwd)" >> "$GITHUB_ENV" cd ../.. - name: Build YYCC + shell: bash run: | chmod +x ./.github/linux_build.sh ./.github/linux_build.sh - name: Run YYCC Test + shell: bash run: | ./bin/install/bin/YYCCTest - name: Run YYCC Benchmark + shell: bash run: | ./bin/install/bin/YYCCBenchmark - name: Upload Built Artifact diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index a8b9d10..9e15239 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,6 +16,7 @@ jobs: ref: 'v1.17.0' path: 'extern/googletest' - name: Build Google Test + shell: bash run: | # Build Google Test cd extern/googletest @@ -26,7 +27,7 @@ jobs: cmake --install . --prefix=../install cd .. cd install - export GTest_ROOT=$(pwd) + echo "GTest_ROOT=$(pwd)" >> "$GITHUB_ENV" cd ../.. - name: Fetch Google Benchmark uses: actions/checkout@v4 @@ -35,6 +36,7 @@ jobs: ref: 'v1.9.4' path: 'extern/benchmark' - name: Build Google Benchmark + shell: bash run: | # Build Google Benchmark cd extern/benchmark @@ -47,16 +49,19 @@ jobs: cmake --install . --prefix=../install cd .. cd install - export benchmark_ROOT=$(pwd) + echo "benchmark_ROOT=$(pwd)" >> "$GITHUB_ENV" cd ../.. - name: Build YYCC + shell: bash run: | chmod +x ./.github/macos_build.sh ./.github/macos_build.sh - name: Run YYCC Test + shell: bash run: | ./bin/install/bin/YYCCTest - name: Run YYCC Benchmark + shell: bash run: | ./bin/install/bin/YYCCBenchmark - name: Upload Built Artifact diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 555f92e..6ae96c9 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -23,17 +23,21 @@ jobs: ref: 'v1.17.0' path: 'extern/googletest' - name: Build Google Test + shell: cmd run: | - # Build Google Test + :: Build Google Test cd extern/googletest - mkdir build install + mkdir build + mkdir install cd build - cmake -DCMAKE_CXX_STANDARD=23 -Dgtest_force_shared_crt=ON -DCMAKE_BUILD_TYPE=Release .. + cmake -A x64 -DCMAKE_CXX_STANDARD=23 -Dgtest_force_shared_crt=ON .. cmake --build . --config Release cmake --install . --prefix=../install --config Release cd .. cd install - set GTest_ROOT=%CD% + :: Idk why I can't use $GITHUB_ENV, so I use this stupid way to do this. + :: This is first entry so we override it. + echo set GTest_ROOT=%CD% > ../../envs.bat cd ../.. - name: Fetch Google Benchmark uses: actions/checkout@v4 @@ -42,27 +46,34 @@ jobs: ref: 'v1.9.4' path: 'extern/benchmark' - name: Build Google Benchmark + shell: cmd run: | - # Build Google Benchmark + :: Build Google Benchmark cd extern/benchmark - # Create symlink to googletest as required by benchmark + :: Create symlink to googletest as required by benchmark mklink /D googletest ../googletest - mkdir build install + mkdir build + mkdir install cd build - cmake -DCMAKE_CXX_STANDARD=23 -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_BUILD_TYPE=Release .. + cmake -A x64 -DCMAKE_CXX_STANDARD=23 -DBENCHMARK_ENABLE_TESTING=OFF .. cmake --build . --config Release cmake --install . --prefix=../install --config Release cd .. cd install - set benchmark_ROOT=%CD% + :: This is second entry so we append it. + echo set benchmark_ROOT=%CD% >> ../../envs.bat cd ../.. - name: Build YYCC shell: cmd run: | + :: Prepare Visual Studio set VS=${{ matrix.vs }} set VCVARS="C:\Program Files (x86)\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" if not exist %VCVARS% set VCVARS="C:\Program Files\Microsoft Visual Studio\%VS%\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" call %VCVARS% ${{ matrix.msvc_arch }} + :: Extract saved environment variables + call .\extern\envs.bat + :: Build Project .\.github\windows_build.bat - name: Run YYCC Test shell: cmd diff --git a/src/yycc/env.cpp b/src/yycc/env.cpp index 3f2b282..21b3865 100644 --- a/src/yycc/env.cpp +++ b/src/yycc/env.cpp @@ -33,6 +33,11 @@ #endif #endif +// Extern POSIX environment variables list. +#if !defined(YYCC_OS_WINDOWS) +extern char** environ; +#endif + #define SAFECAST ::yycc::num::safe_cast #define SAFEOP ::yycc::num::safe_op #define ENC ::yycc::encoding::windows @@ -169,10 +174,6 @@ namespace yycc::env { }; using SmartEnvironmentStrings = std::unique_ptr, EnvironmentStringsDeleter>; -#else - - extern char** environ; - #endif VarResult> get_vars() { diff --git a/test/yycc/windows/console.cpp b/test/yycc/windows/console.cpp index e0c8524..df804ae 100644 --- a/test/yycc/windows/console.cpp +++ b/test/yycc/windows/console.cpp @@ -8,9 +8,10 @@ namespace yycctest::windows::console { #if defined(YYCC_OS_WINDOWS) && defined(YYCC_STL_MSSTL) TEST(WindowsConsole, ColorfulConsole) { - // Set colorful console should always be success. auto rv = CONSOLE::colorful_console(); - EXPECT_TRUE(rv.has_value()); + // Set colorful console should always be success. + // Unless it is not a TTY. + EXPECT_TRUE(rv.has_value() || rv.error() == CONSOLE::ExecError::NotTty); } #endif