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..9d5c32b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +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 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 +RUN apk add --no-cache git +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.