From 0d7317db247d8a7bb7a1681023dadd847f16e5c6 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 27 Sep 2024 21:49:59 +0300 Subject: [PATCH 1/7] build: devcontainer support --- .devcontainer/Dockerfile | 24 +++++++++++++++++++++ .devcontainer/devcontainer.json | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000000..392eb2ec8b0 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,24 @@ +# Use the official VS Code base image for dev containers +FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye + +# Install dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + libssl-dev \ + pkg-config \ + clang \ + cmake \ + llvm \ + curl \ + gnupg \ + lsb-release \ + software-properties-common \ + unzip + +# Install protoc v25.2+ +RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip \ + && unzip protoc-25.2-linux-x86_64.zip -d /usr/local \ + && rm protoc-25.2-linux-x86_64.zip + +# Install wasm-bindgen-cli@0.2.85 +RUN cargo install wasm-bindgen-cli@0.2.85 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000000..27dced45c6c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,37 @@ +{ + "name": "Dash Platform Dev Container", + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "customizations": { + "vscode": { + "settings": {}, + "extensions": [ + "ms-vscode.cpptools", + "ms-vscode.cmake-tools", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "vadimcn.vscode-lldb", + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + ] + } + }, + "remoteUser": "vscode", + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/rust:1": { + "version": 1.80, + "targets": "wasm32-unknown-unknown", + }, + "ghcr.io/devcontainers/features/node:1": { + "version": 20, + "installYarnUsingApt": false, + }, + "ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {}, + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + "postCreateCommand": "cargo install wasm-bindgen-cli@0.2.85" +} From 97974b182d2bd317ac73dd570ac9813cccd71707 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 27 Sep 2024 22:15:29 +0300 Subject: [PATCH 2/7] chore: update plugins and create scripts --- .devcontainer/devcontainer.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 27dced45c6c..88eca88872c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -8,13 +8,18 @@ "vscode": { "settings": {}, "extensions": [ - "ms-vscode.cpptools", + "arcanis.vscode-zipfs", + "chrmarti.regex", + "davidanson.vscode-markdownlint", + "arcanis.vscode-zipfs", "ms-vscode.cmake-tools", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "vadimcn.vscode-lldb", "rust-lang.rust-analyzer", "tamasfe.even-better-toml", + "zhangyue.rust-mod-generator", + "ms-azuretools.vscode-docker" ] } }, @@ -33,5 +38,8 @@ "ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {}, "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} }, - "postCreateCommand": "cargo install wasm-bindgen-cli@0.2.85" + "postCreateCommand": { + "wasm-bindgen-ci": "cargo install wasm-bindgen-cli@0.2.85", + "corepack": "corepack enable && yarn install", + } } From 63b5fcac71881d5fcbee3c3bfc0b1e50bc07c014 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 27 Sep 2024 23:19:16 +0300 Subject: [PATCH 3/7] chore: update plugins and docker file --- .devcontainer/Dockerfile | 38 ++++++++++++++++++++++++++++++--- .devcontainer/devcontainer.json | 17 +++++++++------ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 392eb2ec8b0..0986c998e57 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,5 @@ # Use the official VS Code base image for dev containers -FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye +FROM mcr.microsoft.com/devcontainers/base:ubuntu # Install dependencies RUN apt-get update && apt-get install -y \ @@ -15,10 +15,42 @@ RUN apt-get update && apt-get install -y \ software-properties-common \ unzip +# Switch to clang +RUN rm /usr/bin/cc && ln -s /usr/bin/clang /usr/bin/cc + +ENV CARGO_HOME=/root/.cargo +ENV PATH=$CARGO_HOME/bin:$PATH + +# TODO: It doesn't sharing PATH between stages, so we need "source $HOME/.cargo/env" everywhere +COPY rust-toolchain.toml . +RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | tr -d '"')" && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ + --profile minimal \ + -y \ + --default-toolchain "${TOOLCHAIN_VERSION}" \ + --target wasm32-unknown-unknown + +# Install protoc - protobuf compiler +# The one shipped with Alpine does not work +ARG TARGETARCH +ARG PROTOC_VERSION=25.2 +RUN if [[ "$TARGETARCH" == "arm64" ]] ; then export PROTOC_ARCH=aarch_64; else export PROTOC_ARCH=x86_64; fi; \ + curl -Ls https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-${PROTOC_ARCH}.zip \ + -o /tmp/protoc.zip && \ + unzip -qd /opt/protoc /tmp/protoc.zip && \ + rm /tmp/protoc.zip && \ + ln -s /opt/protoc/bin/protoc /usr/bin/ + # Install protoc v25.2+ RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip \ && unzip protoc-25.2-linux-x86_64.zip -d /usr/local \ && rm protoc-25.2-linux-x86_64.zip -# Install wasm-bindgen-cli@0.2.85 -RUN cargo install wasm-bindgen-cli@0.2.85 +# Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain +# better build caching +RUN if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ + RUSTFLAGS="-C target-feature=-crt-static" \ + # Meanwhile if you want to update wasm-bindgen you also need to update version in: + # - packages/wasm-dpp/Cargo.toml + # - packages/wasm-dpp/scripts/build-wasm.sh + cargo install wasm-bindgen-cli@0.2.86 --locked diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 88eca88872c..9d6cf6b1887 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -25,21 +25,24 @@ }, "remoteUser": "vscode", "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "true", + "username": "vscode", + "userUid": "1000", + "userGid": "1000", + "upgradePackages": "true" + }, "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/github-cli:1": {}, - "ghcr.io/devcontainers/features/rust:1": { - "version": 1.80, - "targets": "wasm32-unknown-unknown", - }, "ghcr.io/devcontainers/features/node:1": { "version": 20, "installYarnUsingApt": false, }, "ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {}, - "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, + "ghcr.io/schlich/devcontainer-features/starship:0": {}, }, "postCreateCommand": { - "wasm-bindgen-ci": "cargo install wasm-bindgen-cli@0.2.85", - "corepack": "corepack enable && yarn install", + "corepack": "COREPACK_ENABLE_NETWORK=1 yarn", } } From 147e92150e1c35be45c8db4eec575f9415dc89de Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 28 Sep 2024 00:00:02 +0300 Subject: [PATCH 4/7] build: fix cargo and git --- .devcontainer/Dockerfile | 27 +++++++++++++++------------ .devcontainer/devcontainer.json | 9 +++++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 0986c998e57..f64e6c05804 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -18,18 +18,6 @@ RUN apt-get update && apt-get install -y \ # Switch to clang RUN rm /usr/bin/cc && ln -s /usr/bin/clang /usr/bin/cc -ENV CARGO_HOME=/root/.cargo -ENV PATH=$CARGO_HOME/bin:$PATH - -# TODO: It doesn't sharing PATH between stages, so we need "source $HOME/.cargo/env" everywhere -COPY rust-toolchain.toml . -RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | tr -d '"')" && \ - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ - --profile minimal \ - -y \ - --default-toolchain "${TOOLCHAIN_VERSION}" \ - --target wasm32-unknown-unknown - # Install protoc - protobuf compiler # The one shipped with Alpine does not work ARG TARGETARCH @@ -46,6 +34,21 @@ RUN curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v25.2 && unzip protoc-25.2-linux-x86_64.zip -d /usr/local \ && rm protoc-25.2-linux-x86_64.zip +# Switch to vscode user +USER vscode + +ENV CARGO_HOME=/home/vscode/.cargo +ENV PATH=$CARGO_HOME/bin:$PATH + +# TODO: It doesn't sharing PATH between stages, so we need "source $HOME/.cargo/env" everywhere +COPY rust-toolchain.toml . +RUN TOOLCHAIN_VERSION="$(grep channel rust-toolchain.toml | awk '{print $3}' | tr -d '"')" && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \ + --profile minimal \ + -y \ + --default-toolchain "${TOOLCHAIN_VERSION}" \ + --target wasm32-unknown-unknown + # Install wasm-bindgen-cli in the same profile as other components, to sacrifice some performance & disk space to gain # better build caching RUN if [[ -z "${SCCACHE_MEMCACHED}" ]] ; then unset SCCACHE_MEMCACHED ; fi ; \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9d6cf6b1887..031422d4424 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -32,7 +32,10 @@ "userGid": "1000", "upgradePackages": "true" }, - "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/git:1": { + "version": "latest", + "ppa": "false" + }, "ghcr.io/devcontainers/features/github-cli:1": {}, "ghcr.io/devcontainers/features/node:1": { "version": 20, @@ -42,7 +45,5 @@ "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, "ghcr.io/schlich/devcontainer-features/starship:0": {}, }, - "postCreateCommand": { - "corepack": "COREPACK_ENABLE_NETWORK=1 yarn", - } + "postCreateCommand": "git config --global --add safe.directory $PWD", } From cda6e3bd02d1f30c58c2188d187c738e3bf56742 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 28 Sep 2024 00:12:02 +0300 Subject: [PATCH 5/7] build: fix docker --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 031422d4424..98743faa7d9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,7 +42,7 @@ "installYarnUsingApt": false, }, "ghcr.io/eitsupi/devcontainer-features/jq-likes:2": {}, - "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/schlich/devcontainer-features/starship:0": {}, }, "postCreateCommand": "git config --global --add safe.directory $PWD", From f6cecda080812b7487e0e210ff5354242bb220c9 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 28 Sep 2024 00:55:01 +0300 Subject: [PATCH 6/7] build: persist rust cache --- .devcontainer/devcontainer.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 98743faa7d9..2047f18405e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -24,6 +24,13 @@ } }, "remoteUser": "vscode", + "mounts": [ + { + "source": "devcontainer-cargo-cache-${devcontainerId}", + "target": "/usr/local/cargo", + "type": "volume" + } + ], "features": { "ghcr.io/devcontainers/features/common-utils:2": { "installZsh": "true", From bad1bfe580e14ad9beb72df2728dd34c2ee70b94 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Sat, 28 Sep 2024 02:02:46 +0300 Subject: [PATCH 7/7] build: persist more granular cache --- .devcontainer/devcontainer.json | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2047f18405e..2d0d18ee904 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -26,8 +26,23 @@ "remoteUser": "vscode", "mounts": [ { - "source": "devcontainer-cargo-cache-${devcontainerId}", - "target": "/usr/local/cargo", + "source": "devcontainer-platform-cargo-registry-index-${devcontainerId}", + "target": "/home/vscode/.cargo/registry", + "type": "volume" + }, + { + "source": "devcontainer-platform-cargo-registry-cache-${devcontainerId}", + "target": "/home/vscode/.cargo/registry/cache", + "type": "volume" + }, + { + "source": "devcontainer-platform-cargo-git-db-${devcontainerId}", + "target": "/home/vscode/.cargo/git/db", + "type": "volume" + }, + { + "source": "devcontainer-platform-target-${devcontainerId}", + "target": "${containerWorkspaceFolder}/target", "type": "volume" } ], @@ -52,5 +67,8 @@ "ghcr.io/devcontainers/features/docker-in-docker:2": {}, "ghcr.io/schlich/devcontainer-features/starship:0": {}, }, - "postCreateCommand": "git config --global --add safe.directory $PWD", + "postCreateCommand": { + "git-safe": "git config --global --add safe.directory ${containerWorkspaceFolder}", + "cargo-permissions": "sudo chown -R vscode:vscode /home/vscode/.cargo ${containerWorkspaceFolder}/target" + } }