From 5baec4a6b4076e8e92cfde314f04cf944bee09c5 Mon Sep 17 00:00:00 2001 From: resolritter <17429390+resolritter@users.noreply.github.com> Date: Sat, 29 Apr 2023 22:39:25 -0300 Subject: [PATCH 1/2] provide way of building zigup on Docker --- .dockerignore | 5 +++++ .github/workflows/docker.yml | 39 ++++++++++++++++++++++++++++++++++++ Dockerfile | 28 ++++++++++++++++++++++++++ README.md | 20 ++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d894223 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/.git +/zig-cache +/zig-out +/dep +/scratch diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..4463b50 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,39 @@ +name: Docker + +on: + push: + branches: + - master + pull_request: + branches: + - master + types: + - opened + - synchronize + - reopened + - unlocked + +jobs: + build: + concurrency: + group: docker-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Build zigup on Docker + run: docker build -t zigup . + + - name: Pull zigup from the built image + run: | + container="$(docker container create zigup)" + docker container cp "$container":/zigup/zig-out/bin/zigup . + + - name: Verify zigup binary + run: | + if ldd ./zigup; then + >&2 echo "zigup was not compiled as a static binary" + exit 1 + fi + ./zigup --help diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7991e73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM docker.io/library/alpine:latest + +# Update the system +RUN apk update && apk upgrade + +# Initialize build tools directory +RUN mkdir -p /tools +WORKDIR /tools + +# Install Zig +RUN apk add --no-cache git curl tar xz +ARG ZIG_VERSION=0.11.0-dev.1507+6f13a725a +RUN curl -sSfL \ + https://ziglang.org/builds/zig-linux-x86_64-"$ZIG_VERSION".tar.xz \ + -o zig.tar.xz && \ + tar -xf zig.tar.xz && \ + mv zig-linux-x86_64-"$ZIG_VERSION" zig +ENV PATH="/tools/zig:$PATH" + +# Build zigup +ARG ZIGUP_TARGET=x86_64-linux +ARG ZIGUP_BUILD_FLAGS=-Drelease-safe +COPY . /zigup +WORKDIR /zigup +RUN zig build -Dfetch -Dtarget="$ZIGUP_TARGET" $ZIGUP_BUILD_FLAGS +ENV PATH="/zigup/zig-out/bin:$PATH" + +ENTRYPOINT ["/zigup/zig-out/bin/zigup"] diff --git a/README.md b/README.md index 4a494c2..83bded0 100644 --- a/README.md +++ b/README.md @@ -40,14 +40,34 @@ zigup stores each compiler in a global "install directory" in a versioned subdir zigup makes the zig program available by creating an entry in a directory that occurs in the `PATH` environment variable. On posix systems this entry is a symlink to one of the `zig` executables in the install directory. On windows this is an executable that forwards invocations to one of the `zig` executables in the install directory. Both the "install directory" and "path link" are configurable through command-line options `--install-dir` and `--path-link` respectively. + # Building +## Directly on your host + Run `zig build` to build, `zig build test` to test and install with: ``` # install to a bin directory with cp zig-out/bin/zigup BIN_PATH ``` +## Through Docker + +```bash +# Build for the default target (x86_64-linux) +docker build -t zigup . +# Or specify a custom target through ZIGUP_TARGET +# docker build -t zigup --build-arg ZIGUP_TARGET=macos-x86_64 . + +# Copy zigup from the Docker image to your host +container="$(docker container create zigup)" +docker container cp "$container":/zigup/zig-out/bin/zigup . +docker container rm "$container" + +# Use zigup +./zigup --help +``` + # TODO * set/remove compiler in current environment without overriding the system-wide vesrion. From 321c288299629becb8f7590d86f21fd16bbe3afb Mon Sep 17 00:00:00 2001 From: resolritter <17429390+resolritter@users.noreply.github.com> Date: Sat, 29 Apr 2023 23:45:18 -0300 Subject: [PATCH 2/2] move git install to zigup step --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7991e73..9d5c32b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN mkdir -p /tools WORKDIR /tools # Install Zig -RUN apk add --no-cache git curl tar xz +RUN apk add --no-cache curl tar xz ARG ZIG_VERSION=0.11.0-dev.1507+6f13a725a RUN curl -sSfL \ https://ziglang.org/builds/zig-linux-x86_64-"$ZIG_VERSION".tar.xz \ @@ -18,6 +18,7 @@ RUN curl -sSfL \ ENV PATH="/tools/zig:$PATH" # Build zigup +RUN apk add --no-cache git ARG ZIGUP_TARGET=x86_64-linux ARG ZIGUP_BUILD_FLAGS=-Drelease-safe COPY . /zigup