Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide way of building zigup through Docker #88

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.git
/zig-cache
/zig-out
/dep
/scratch
39 changes: 39 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down