From 7c68294be4e454808da71171c250805051cf2e49 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 14 Aug 2024 14:33:44 +0000 Subject: [PATCH 01/14] Add devcontainer json --- .devcontainer/devcontainer.json | 17 +++++++++++++++++ .devcontainer/postCreate.sh | 12 ++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/postCreate.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..d1fee988be --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "ReScript Compiler", + "build": { + "context": "..", + "dockerfile": "../docker/Dockerfile" + }, + "features": {}, + "customizations": { + "vscode": { + "extensions": [ + "chenglou92.rescript-vscode", + "biomejs.biome" + ] + } + }, + "postCreateCommand": ".devcontainer/postCreate.sh" +} diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100755 index 0000000000..32ec9824ff --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Install dev dependencies from OPAM +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)' >> ~/.bashrc + +npm install --ignore-scripts From 570186559baad13f930828f05ef4f0bbd2a147f3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 14 Aug 2024 14:51:09 +0000 Subject: [PATCH 02/14] Add GitHub CLI feature --- .devcontainer/devcontainer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d1fee988be..ccda29d7ab 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,9 @@ "context": "..", "dockerfile": "../docker/Dockerfile" }, - "features": {}, + "features": { + "ghcr.io/devcontainers/features/github-cli:1":{} + }, "customizations": { "vscode": { "extensions": [ From ee166736d1998ec4cf6255058f9e7011c95ed661 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 14 Aug 2024 17:36:26 +0200 Subject: [PATCH 03/14] Try and create user instead of root. --- .devcontainer/devcontainer.json | 3 ++- docker/Dockerfile | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ccda29d7ab..a5eacb405c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,5 +15,6 @@ ] } }, - "postCreateCommand": ".devcontainer/postCreate.sh" + "postCreateCommand": ".devcontainer/postCreate.sh", + "remoteUser": "devuser" } diff --git a/docker/Dockerfile b/docker/Dockerfile index b7e011e901..c7a633618b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,12 +2,28 @@ 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 +RUN apt update && apt install -y --no-install-recommends sudo 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 +# Create a non-root user and switch to it +ARG USERNAME=devuser +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && usermod -aG sudo $USERNAME \ + && mkdir /workspaces \ + && chown -R $USERNAME:$USERNAME /workspaces + +# Allow the devuser to use sudo without a password +RUN echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +USER $USERNAME + # 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 From 7583828a7298eb4dd310c52841c855fa8bb5fffc Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 14 Aug 2024 16:02:53 +0000 Subject: [PATCH 04/14] Default to bash --- .devcontainer/devcontainer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a5eacb405c..7bc73fcb4a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,7 +12,10 @@ "extensions": [ "chenglou92.rescript-vscode", "biomejs.biome" - ] + ], + "settings": { + "terminal.integrated.defaultProfile.linux": "bash" + } } }, "postCreateCommand": ".devcontainer/postCreate.sh", From e78c73ee442a8136df58d6d19b27717ce5ac3e6b Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 19 Aug 2024 09:44:20 +0000 Subject: [PATCH 05/14] Simplify Dockerfile and devcontainer --- .devcontainer/Dockerfile | 10 ++++++++++ .devcontainer/devcontainer.json | 20 +++++++++++--------- .devcontainer/postCreate.sh | 9 +++++++-- docker/Dockerfile | 30 ------------------------------ 4 files changed, 28 insertions(+), 41 deletions(-) create mode 100644 .devcontainer/Dockerfile delete mode 100644 docker/Dockerfile diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..6ecf5d9bb2 --- /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 update && apt install -y --no-install-recommends opam musl-tools python-is-python3 + +# 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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 7bc73fcb4a..2fbc84ab1c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,23 +1,25 @@ { "name": "ReScript Compiler", "build": { - "context": "..", - "dockerfile": "../docker/Dockerfile" + "context": ".", + "dockerfile": "Dockerfile" }, "features": { - "ghcr.io/devcontainers/features/github-cli:1":{} + "ghcr.io/devcontainers/features/github-cli:1":{ + "installDirectlyFromGitHubRelease": true, + "version": "latest" + }, + "ghcr.io/devcontainers/features/node:1": { + "version":"20" + } }, "customizations": { "vscode": { "extensions": [ "chenglou92.rescript-vscode", "biomejs.biome" - ], - "settings": { - "terminal.integrated.defaultProfile.linux": "bash" - } + ] } }, - "postCreateCommand": ".devcontainer/postCreate.sh", - "remoteUser": "devuser" + "postCreateCommand": ".devcontainer/postCreate.sh" } diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 32ec9824ff..ac84181a3a 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -1,4 +1,9 @@ -#!/bin/bash +#!/bin/sh + +# Opam stuff post install +opam init -y --bare --disable-sandboxing git+https://github.com/rescript-lang/opam-repository +opam switch create 5.2.0 --packages ocaml-option-static +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 # Install dev dependencies from OPAM opam install . --deps-only -y @@ -7,6 +12,6 @@ opam install . --deps-only -y opam install ocaml-lsp-server -y # Add OPAM environment setup to shell startup script -echo 'eval $(opam env)' >> ~/.bashrc +echo 'eval $(opam env)' >> ~/.zshrc npm install --ignore-scripts diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index c7a633618b..0000000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,30 +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 sudo 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 - -# Create a non-root user and switch to it -ARG USERNAME=devuser -ARG USER_UID=1000 -ARG USER_GID=$USER_UID - -RUN groupadd --gid $USER_GID $USERNAME \ - && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ - && usermod -aG sudo $USERNAME \ - && mkdir /workspaces \ - && chown -R $USERNAME:$USERNAME /workspaces - -# Allow the devuser to use sudo without a password -RUN echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers - -USER $USERNAME - -# 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 From 8f2460093ec574204bdde68986b4b90ddfdf5284 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 20 Aug 2024 06:27:07 +0000 Subject: [PATCH 06/14] Move opam install to postCreate --- .devcontainer/Dockerfile | 12 ++++++------ .devcontainer/postCreate.sh | 5 +---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 6ecf5d9bb2..7409de721b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,9 +2,9 @@ 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 update && apt install -y --no-install-recommends opam musl-tools python-is-python3 - -# 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 +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/postCreate.sh b/.devcontainer/postCreate.sh index ac84181a3a..ea808e6330 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -1,11 +1,8 @@ #!/bin/sh -# Opam stuff post install +# Install dev dependencies from OPAM opam init -y --bare --disable-sandboxing git+https://github.com/rescript-lang/opam-repository opam switch create 5.2.0 --packages ocaml-option-static -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 - -# Install dev dependencies from OPAM opam install . --deps-only -y # For IDE support, install the OCaml language server From bea02bdf077bc22a0252f8383614823c27918d7c Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 20 Aug 2024 10:04:42 +0000 Subject: [PATCH 07/14] Add ocamllabs.ocaml-platform extension --- .devcontainer/devcontainer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2fbc84ab1c..783a63c094 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -16,6 +16,7 @@ "customizations": { "vscode": { "extensions": [ + "ocamllabs.ocaml-platform", "chenglou92.rescript-vscode", "biomejs.biome" ] From 582dc510a81ae3ed21766a613762ff8440e5f2e1 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 20 Aug 2024 14:06:06 +0000 Subject: [PATCH 08/14] Add extensions --- .devcontainer/devcontainer.json | 3 ++- .vscode/extensions.json | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 783a63c094..56cc8e1ff0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -18,7 +18,8 @@ "extensions": [ "ocamllabs.ocaml-platform", "chenglou92.rescript-vscode", - "biomejs.biome" + "biomejs.biome", + "rust-lang.rust-analyzer" ] } }, diff --git a/.vscode/extensions.json b/.vscode/extensions.json index d1554f724c..ba42f037ac 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,12 @@ { - "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" + "esbenp.prettier-vscode", ] } From 3204bb6e488e5f550b73fbffa0bb961d3cd27e57 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 20 Aug 2024 16:33:22 +0200 Subject: [PATCH 09/14] Remove trailing comma --- .vscode/extensions.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index ba42f037ac..67d6332324 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,12 +1,12 @@ { "recommendations": [ - "biomejs.biome", - "chenglou92.rescript-vscode", + "biomejs.biome", + "chenglou92.rescript-vscode", "ocamllabs.ocaml-platform", "rust-lang.rust-analyzer" ], "unwantedRecommendations": [ "dbaeumer.vscode-eslint", - "esbenp.prettier-vscode", + "esbenp.prettier-vscode" ] } From 25f883ad33ea06ab4a4088f132f65fe83684c70f Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 20 Aug 2024 16:35:41 +0200 Subject: [PATCH 10/14] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From 8e6a359118ee92c905e72eaef5f00fa5411bd1b3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 21 Aug 2024 06:56:16 +0000 Subject: [PATCH 11/14] Add opam env to bashrc --- .devcontainer/postCreate.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index ea808e6330..358b51b53a 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -10,5 +10,6 @@ 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 From 535c0e59e85d18d4e571e49c2fe6570020ff6ac0 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 21 Aug 2024 16:10:51 +0000 Subject: [PATCH 12/14] Update contributing --- CONTRIBUTING.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b97585a998..3645645162 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 + +The repository additionally provides [development container](https://containers.dev/) definition that can be used with [VSCode's Remote Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) - use it to get stable development environment. + +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: From c4433686a6b93e856cbe99508aab18558d48f542 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 23 Aug 2024 08:11:33 +0200 Subject: [PATCH 13/14] Update CONTRIBUTING.md Co-authored-by: Christoph Knittel --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3645645162..d5f4785b1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -61,7 +61,7 @@ Run `npm install --ignore-scripts`. This will install the npm dependencies requi ### B. Devcontainer -The repository additionally provides [development container](https://containers.dev/) definition that can be used with [VSCode's Remote Containers extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) - use it to get stable development environment. +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. From 69b9a9727598d5045d3c9a92fb8744addf3d17cc Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Fri, 23 Aug 2024 08:11:41 +0200 Subject: [PATCH 14/14] Update .devcontainer/postCreate.sh Co-authored-by: Christoph Knittel --- .devcontainer/postCreate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 358b51b53a..c7965afff0 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -1,7 +1,7 @@ #!/bin/sh # Install dev dependencies from OPAM -opam init -y --bare --disable-sandboxing git+https://github.com/rescript-lang/opam-repository +opam init -y --bare --disable-sandboxing opam switch create 5.2.0 --packages ocaml-option-static opam install . --deps-only -y