From bfbb477f60cdee892086d1ec81f00340809da359 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 15 Feb 2025 00:03:19 -0500 Subject: [PATCH] CI Attempt --- .gitea/workflows/build.yml | 33 +++++++++++++++++++++++++++++++++ README.md | 2 +- example/build.sh | 2 ++ example/guest/src/example.c | 2 ++ lib/include/trampoline/types.h | 9 ++++++--- lib/src/syscall.cpp | 2 +- scripts/install-dependencies.sh | 13 +++++++++++++ src/main.cpp | 2 +- 8 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 .gitea/workflows/build.yml create mode 100755 scripts/install-dependencies.sh diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..1d92304 --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,33 @@ +name: 'CI' +on: + push: + branches: + - master + +# Jobs +jobs: + # Test Project + test: + strategy: + fail-fast: false + matrix: + arch: + - AMD64 + - ARM64 + name: Test + runs-on: ${{ startsWith(matrix.arch, 'ARM') && 'raspberry-pi' || 'ubuntu-latest' }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + # Dependencies + - name: Install Dependencies + run: ./scripts/install-dependencies.sh + # Build + - name: Build + run: ./example/build.sh + # Test + - name: Test (Pipe-Based) + run: MCPI_USE_PIPE_TRAMPOLINE=1 ./example/run.sh + - name: Test (Syscall-Based) + run: ./example/run.sh + if: ${{ ! startsWith(matrix.arch, 'ARM') }} \ No newline at end of file diff --git a/README.md b/README.md index 4697e5b..8646ec2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This is a simple program allowing ARM32 code to easily call "native" code. By running an ARM32 program inside this runtime, it gains the ability to call `raw_trampoline()`. This function copies its arguments and passes them to the "host" code. -The runtime also automatically uses QEMU on x86_64 systems. +The runtime also automatically uses QEMU on non-ARM systems. ## Terminology - "Guest" code is the main ARM32 program. It is running inside the runtime. diff --git a/example/build.sh b/example/build.sh index df2799a..ca2db5a 100755 --- a/example/build.sh +++ b/example/build.sh @@ -1,6 +1,7 @@ #!/bin/sh set -e +cd "$(dirname "$0")" # Run Script RUN="$(pwd)/run.sh" @@ -10,6 +11,7 @@ out() { } out '#!/bin/sh' out 'set -e' +out 'cd "$(dirname "$0")"' chmod +x "${RUN}" # Create Build Directory diff --git a/example/guest/src/example.c b/example/guest/src/example.c index df0158e..4e8a5bc 100644 --- a/example/guest/src/example.c +++ b/example/guest/src/example.c @@ -16,6 +16,8 @@ void run(uint32_t cmd, const char *str) { // Main #define INFO(str) fprintf(stderr, "==== %s ====\n", str) int main() { + // Check Trampoline Type + fprintf(stderr, "Using Pipe-Based Trampoline: %i\n", is_trampoline_pipe_based()); // Normal Calls INFO("Testing Normal Trampoline Calls"); run(0, "Hello World!"); diff --git a/lib/include/trampoline/types.h b/lib/include/trampoline/types.h index 053c028..4294c19 100644 --- a/lib/include/trampoline/types.h +++ b/lib/include/trampoline/types.h @@ -1,6 +1,7 @@ #pragma once #include +#include // C++ Support #ifdef __cplusplus @@ -30,11 +31,13 @@ typedef trampoline_raw_t *trampoline_t; #endif // Environmental Variables -#ifdef __cplusplus -#define ENV(name, ...) constexpr const char *name##_ENV = #name; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-variable" +#define ENV(name, ...) static const char *name##_ENV = #name; #include "env-list.h" #undef ENV -#endif +#pragma GCC diagnostic pop +#define is_trampoline_pipe_based() (getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) != NULL) // Call Trampoline From Guest Code #ifndef MCPI_BUILD_RUNTIME diff --git a/lib/src/syscall.cpp b/lib/src/syscall.cpp index 0241ce3..dfaf0d9 100644 --- a/lib/src/syscall.cpp +++ b/lib/src/syscall.cpp @@ -5,7 +5,7 @@ // Check bool SyscallTrampoline::should_use() { - return getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr; + return !is_trampoline_pipe_based(); } // Call diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh new file mode 100755 index 0000000..b8c587b --- /dev/null +++ b/scripts/install-dependencies.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +set -e + +apt-get update +apt-get install -y --no-install-recommends \ + cmake \ + ninja-build \ + gcc g++ \ + python3 \ + python3-venv \ + python3-tomli \ + libglib2.0-dev \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a22fc3c..f20c02c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) { // Create Implementation Implementation *impl = new PipeImplementation; #ifdef MCPI_HAS_QEMU - if (getenv(MCPI_USE_PIPE_TRAMPOLINE_ENV) == nullptr) { + if (!is_trampoline_pipe_based()) { delete impl; impl = new SyscallImplementation; }