diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 5d9344b..5eac5ca 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,7 +2,11 @@ FROM ubuntu:24.04 RUN apt-get update && \ apt-get install -y build-essential clang clang-format clang-tidy git python3-pip \ - libssl-dev ninja-build && \ - pip3 install conan + libssl-dev ninja-build curl && \ + pip3 install conan && \ + curl -L https://ziglang.org/builds/zig-linux-x86_64-0.14.1.tar.xz \ + | tar -xJ && \ + mv zig-linux-x86_64-0.14.1 /opt/zig && \ + ln -s /opt/zig/zig /usr/local/bin/zig WORKDIR /workspace diff --git a/README.md b/README.md index 14f2d43..755014a 100644 --- a/README.md +++ b/README.md @@ -29,21 +29,11 @@ g++ -std=c++23 ouro_lang.cc -o ouro_lang ./ouro_lang ``` -Legacy CMake files remain for compatibility and can be used instead of Zig: - -```bash -mkdir build && cd build -cmake .. -cmake --build . -- -j\$(nproc) -``` +A Zig build script is also included (`build.zig`) for environments with the Zig compiler installed. It compiles the C portions of the project using the C23 standard and links against LLVM in addition to `libc`. The script mirrors the old CMake setup and exposes tasks for running the module example and its unit tests. If Zig is missing locally, run `scripts/install_zig.sh` to download version `0.14.1`. ## Repository Structure -The source tree contains C and C++ code alongside a `build.zig` script. -Zig's build system is used to compile the interpreter and modules. A -CMake configuration is kept in `cmake/` for environments that still -depend on it. - +The project includes tests, a development container, and extensive documentation. ## Zig Build with Modules The `ouro_mod` directory showcases a minimal C++23 module setup. Build and run the modular example with: diff --git a/scripts/install_zig.sh b/scripts/install_zig.sh new file mode 100755 index 0000000..ab7876a --- /dev/null +++ b/scripts/install_zig.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +ZIG_VERSION="0.14.1" +ZIG_DIR="zig-x86_64-linux-${ZIG_VERSION}" +ARCHIVE="zig-linux-x86_64-${ZIG_VERSION}.tar.xz" +DOWNLOAD_URL="https://ziglang.org/builds/${ARCHIVE}" + +if command -v zig >/dev/null 2>&1; then + INSTALLED=$(zig version) + if [ "$INSTALLED" = "$ZIG_VERSION" ]; then + echo "Zig ${ZIG_VERSION} already installed" + exit 0 + fi +fi + +rm -f "$ARCHIVE" + +if [ ! -d "$ZIG_DIR" ]; then + echo "Downloading Zig ${ZIG_VERSION}..." + curl -L -o "$ARCHIVE" "$DOWNLOAD_URL" + mkdir -p "$ZIG_DIR" + tar -xf "$ARCHIVE" -C "$ZIG_DIR" --strip-components=1 +fi + +cat < zig +#!/usr/bin/env bash +"$(pwd)/${ZIG_DIR}/zig" "$@" +SH +chmod +x zig + +echo "Zig ${ZIG_VERSION} installed in $(pwd)/${ZIG_DIR}"