Skip to content

Latest commit

 

History

History
58 lines (43 loc) · 1.58 KB

README.md

File metadata and controls

58 lines (43 loc) · 1.58 KB

Protohackers in Zig

I'm solving the protohackers in Zig to learn more about networking and continue learning Zig.

Each problem has it's corresponding file in src, e.g. src/01_smoke_test.zig. The common logic is extracted in different files, e.g. src/tcp_server.zig.

I used CLI arguments to run a specific problem. To run the smoke test, run:

# Smoke test
zig build run -- 00

# Prime time
zig build run -- 01

Docker

I dockerized this project to be run in any server. The images are exposed in Github Container Registry here.

Building the images:

docker buildx build --platform linux/arm64,linux/amd64 -t ghcr.io/rlopzc/protohackers_zig:latest --push .

Running the image in any cloud provider

  1. Create a server in a cloud provider (I used Hetzner)

  2. Pull the image. You can either pull the latest, which should contain most solutions, or a specific tag with a solution.

    docker pull ghcr.io/rlopzc/protohackers_zig:0_smoke
    # or
    docker pull ghcr.io/rlopzc/protohackers_zig:latest
  3. Run the image. Remember to pass the problem number as an argument.

    docker run --rm --name protohackers_zig -p 3000:3000 --init ghcr.io/rlopzc/protohackers_zig:latest 00
  4. Run the protohacker test using their website!

Upgrading Zig

# Zig version
mise install zig@version
mise use --global zig@version

# Build zls
git checkout {tag}
zig build -Doptimize=ReleaseSafe
ln -sf ~/packages/zls/zig-out/bin/zls ~/.local/bin/zls