From d6bb511810fcb850f1a5f2cb1d4c2a14e7d00081 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Fri, 29 Dec 2023 17:52:44 +0100 Subject: [PATCH] CI: Add arch cross-compile and test (#1) --- .github/workflows/arch.yml | 71 ++++++++++++++++++++++++++++++++++++++ src/config.cpp | 2 +- tests/main.cpp | 3 ++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/arch.yml diff --git a/.github/workflows/arch.yml b/.github/workflows/arch.yml new file mode 100644 index 0000000..9762991 --- /dev/null +++ b/.github/workflows/arch.yml @@ -0,0 +1,71 @@ +name: Build & Test (Arch) + +on: [push, pull_request, workflow_dispatch] +jobs: + gcc: + name: "gcc build / clang test" + runs-on: ubuntu-latest + container: + image: archlinux + steps: + - name: Checkout repository actions + uses: actions/checkout@v4 + with: + sparse-checkout: .github/actions + + - name: Get required pkgs + run: | + sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf + pacman --noconfirm --noprogressbar -Syyu + pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang + + - name: Build with gcc + run: | + CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build + CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + cp ./build/libhyprlang.so /usr/lib + + - name: Build with clang + run: | + rm -rf ./build + CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build + CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + rm ./build/libhyprlang.so + + - name: Run tests + run: | + cd ./tests && ../build/hyprlang_test + + clang: + name: "clang build / gcc test" + runs-on: ubuntu-latest + container: + image: archlinux + steps: + - name: Checkout repository actions + uses: actions/checkout@v4 + with: + sparse-checkout: .github/actions + + - name: Get required pkgs + run: | + sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf + pacman --noconfirm --noprogressbar -Syyu + pacman --noconfirm --noprogressbar -Sy gcc base-devel cmake clang + + - name: Build with clang + run: | + CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build + CC="/usr/bin/clang" CXX="/usr/bin/clang++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + cp ./build/libhyprlang.so /usr/lib + + - name: Build with gcc + run: | + rm -rf ./build + CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -S . -B ./build + CC="/usr/bin/gcc" CXX="/usr/bin/g++" cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + rm ./build/libhyprlang.so + + - name: Run tests + run: | + cd ./tests && ../build/hyprlang_test diff --git a/src/config.cpp b/src/config.cpp index 4272ecd..e887838 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -39,7 +39,7 @@ CConfig::CConfig(const char* path) { impl->envVariables.clear(); for (char** env = environ; *env; ++env) { - const std::string ENVVAR = *env; + const std::string ENVVAR = *env ? *env : ""; const auto VARIABLE = ENVVAR.substr(0, ENVVAR.find_first_of('=')); const auto VALUE = ENVVAR.substr(ENVVAR.find_first_of('=') + 1); impl->envVariables.push_back({VARIABLE, VALUE}); diff --git a/tests/main.cpp b/tests/main.cpp index dbebe2c..e8f260e 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -52,6 +52,9 @@ int main(int argc, char** argv, char** envp) { int ret = 0; try { + if (!getenv("SHELL")) + setenv("SHELL", "/bin/sh", true); + std::cout << "Starting test\n"; Hyprlang::CConfig config("./config/config.conf");