🌟

zigのdevcontainerでの環境構築

2023/10/23に公開

特にまとめているやつがなかったので描きます。

.devcontainer/Dockerfile
FROM --platform=linux/amd64 mcr.microsoft.com/vscode/devcontainers/base:0-bullseye

ENV DEBIAN_FRONTEND=noninteractive
RUN apt update  &&  apt upgrade -y

# install zig
ENV ZIG_VERSION=0.11.0
RUN wget "https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar.xz"
RUN tar Jxvf "zig-linux-x86_64-${ZIG_VERSION}.tar.xz" -C /usr/local && rm "zig-linux-x86_64-${ZIG_VERSION}.tar.xz"
RUN mv /usr/local/zig-linux-x86_64-${ZIG_VERSION} /usr/local/zig-linux
ENV PATH=/usr/local/zig-linux:${PATH}

# install language server 
# https://github.com/zigtools/zls/releases/tag/0.11.0
ENV ZLS_VERSION=0.11.0
RUN wget "https://github.com/zigtools/zls/releases/download/${ZLS_VERSION}/zls-x86_64-linux.tar.gz"

RUN tar zxvf zls-x86_64-linux.tar.gz -C /usr/local && rm zls-x86_64-linux.tar.gz
# executable permission.
RUN chmod ugo+x /usr/local/bin/zls
.devcontainer.json
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
	"name": "Debian",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	// "image": "mcr.microsoft.com/devcontainers/base:jammy",
	"build": {
		"dockerfile": "Dockerfile",
		"args": {
			// Update 'VARIANT' to pick a .NET Core version: 6.0, 7.0
			"VARIANT": "bullseye"
		}
	},

	// Features to add to the dev container. More info: https://containers.dev/features.
	// "features": {},

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Use 'postCreateCommand' to run commands after the container is created.
	// "postCreateCommand": "uname -a",

	// Configure tool-specific properties.
	"customizations": {
		"vscode": {
			"extensions": [
				"ziglang.vscode-zig"
			],
			"settings": {
				"zig.path": "/usr/local/zig-linux/zig",
				"zig.buildFilePath": "${workspaceFolder}/build.zig"
			}
		}
	}

	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

Discussion