diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..7409de721b --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm +LABEL org.opencontainers.image.authors="Christoph Knittel " +LABEL org.opencontainers.image.description="Docker image for ReScript development." + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + opam \ + musl-tools \ + python-is-python3 \ + && rm -rf /var/lib/apt/lists/* diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..56cc8e1ff0 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,27 @@ +{ + "name": "ReScript Compiler", + "build": { + "context": ".", + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/github-cli:1":{ + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/node:1": { + "version":"20" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ocamllabs.ocaml-platform", + "chenglou92.rescript-vscode", + "biomejs.biome", + "rust-lang.rust-analyzer" + ] + } + }, + "postCreateCommand": ".devcontainer/postCreate.sh" +} diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100755 index 0000000000..c7965afff0 --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +# Install dev dependencies from OPAM +opam init -y --bare --disable-sandboxing +opam switch create 5.2.0 --packages ocaml-option-static +opam install . --deps-only -y + +# For IDE support, install the OCaml language server +opam install ocaml-lsp-server -y + +# Add OPAM environment setup to shell startup script +echo 'eval $(opam env)' >> ~/.zshrc +echo 'eval $(opam env)' >> ~/.bashrc + +npm install --ignore-scripts diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d1554f724c..67d6332324 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,10 @@ { - "recommendations": ["biomejs.biome", "chenglou92.rescript-vscode"], + "recommendations": [ + "biomejs.biome", + "chenglou92.rescript-vscode", + "ocamllabs.ocaml-platform", + "rust-lang.rust-analyzer" + ], "unwantedRecommendations": [ "dbaeumer.vscode-eslint", "esbenp.prettier-vscode" diff --git a/CHANGELOG.md b/CHANGELOG.md index 633db87633..796a10a892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,10 @@ - Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953 - Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963 +#### :house: Internal + +- Add dev container. https://github.com/rescript-lang/rescript-compiler/pull/6962 + # 12.0.0-alpha.1 #### :rocket: New Feature diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b97585a998..d5f4785b1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,11 @@ git clone --depth 1 https://github.com/rescript-lang/rescript-compiler.git This will only consume less than 50MB. -## Install OCaml compiler + dependencies +## Installation + +### A. Manual installation + +#### Install OCaml compiler + dependencies The ReScript compiler compiles with any recent OCaml compiler. We are using `dune` as a build system for easy workflows and proper IDE support. @@ -51,10 +55,18 @@ opam install . --deps-only opam install ocaml-lsp-server ``` -## npm install +#### npm install Run `npm install --ignore-scripts`. This will install the npm dependencies required for the build scripts. +### B. Devcontainer + +As an alternative to the manual installation, the repository provides a [development container](https://containers.dev/) definition that can be used with [VS Code's Remote Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers). Use this to get a stable development environment without having to install anything locally other than VS Code and Docker. + +Run the `Dev Containers: Rebuild and Reopen in Container` action to get started. + +You can also open this dev container with [GitHub Codespaces](https://github.com/features/codespaces/). + ## Building the Compiler The compiler binaries themselves can be built directly with dune as follows: diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index b7e011e901..0000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM rust:1.80.1-bullseye -LABEL org.opencontainers.image.authors="Christoph Knittel " -LABEL org.opencontainers.image.description="Docker image for ReScript development." - -RUN apt update && apt install -y --no-install-recommends ca-certificates curl git rsync opam musl-tools python3 python-is-python3 - -# Node.js -RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - -RUN apt install -y nodejs - -# OCaml -RUN opam init -y --bare --disable-sandboxing git+https://github.com/rescript-lang/opam-repository -RUN opam switch create 5.2.0 --packages ocaml-option-static -RUN opam install -y dune cppo=1.6.9 js_of_ocaml-compiler=5.8.1 ocamlformat=0.26.2 ounit2=2.2.7 reanalyze=2.25.1 \ No newline at end of file