Skip to content

Commit 4b72e67

Browse files
Integrate compact dev tools (#218)
Signed-off-by: Andrew Fleming <fleming.andrew@protonmail.com> Co-authored-by: ⟣ €₥ℵ∪ℓ ⟢ <34749913+emnul@users.noreply.github.com>
1 parent 511bb81 commit 4b72e67

12 files changed

Lines changed: 2252 additions & 284 deletions

File tree

.github/workflows/test.yml

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -26,81 +26,57 @@ jobs:
2626
- name: Setup Environment
2727
uses: ./.github/actions/setup
2828

29-
- name: Install Compact compiler
30-
id: setup
29+
- name: Install Compact developer tools
3130
shell: bash
3231
run: |
33-
set -euo pipefail
34-
# Create directory for compiler
35-
COMPACT_HOME="$HOME/compactc"
36-
mkdir -p "$COMPACT_HOME"
37-
38-
# Create URL
39-
ZIP_FILE="compactc_v${COMPILER_VERSION}_x86_64-unknown-linux-musl.zip"
40-
DOWNLOAD_URL="https://d3fazakqrumx6p.cloudfront.net/artifacts/compiler/compactc_${COMPILER_VERSION}/${ZIP_FILE}"
41-
42-
echo "⬇️ Downloading Compact compiler..."
43-
curl -Ls "$DOWNLOAD_URL" -o "$COMPACT_HOME/compactc.zip"
44-
45-
echo "📦 Extracting..."
46-
unzip -q "$COMPACT_HOME/compactc.zip" -d "$COMPACT_HOME"
47-
chmod +x "$COMPACT_HOME"/{compactc,compactc.bin,zkir}
48-
49-
echo "📁 Setting environment variables..."
50-
echo "COMPACT_HOME=$COMPACT_HOME" >> "$GITHUB_ENV"
51-
echo "$COMPACT_HOME" >> "$GITHUB_PATH"
52-
53-
echo "✅ Verifying installation..."
54-
if [ ! -f "$COMPACT_HOME/compactc" ]; then
55-
echo "::error::❌ compactc not found in $COMPACT_HOME"
56-
exit 1
57-
fi
32+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/midnightntwrk/compact/releases/latest/download/compact-installer.sh | sh
33+
echo "$HOME/.compact/bin" >> "$GITHUB_PATH"
5834
35+
- name: Install and verify toolchain
36+
run: |
37+
compact update ${{ env.COMPILER_VERSION }}
5938
echo "🤖 Testing installation..."
60-
"$COMPACT_HOME/compactc" --version
39+
compact compile --version
40+
compact compile --language-version
6141
6242
- name: Check compiler and language version
6343
run: |
64-
COMPILER_OUTPUT=$(compactc --version)
65-
COMPUTED_COMPILER_VERSION=$(echo "$COMPILER_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | head -n 1)
66-
if [ "$COMPUTED_COMPILER_VERSION" != "$COMPILER_VERSION" ]; then
67-
errMsg="❌ Compiler version mismatch!%0AExpected: $COMPILER_VERSION%0AGot: $COMPUTED_COMPILER_VERSION"
44+
# Check toolchain version
45+
COMPILER_OUTPUT=$(compact compile --version)
46+
COMPUTED_COMPILER_VERSION=$(echo "$COMPILER_OUTPUT" | grep -oP '\b[0-9]+\.[0-9]+\.[0-9]+\b' | head -n 1)
47+
if [ "$COMPUTED_COMPILER_VERSION" != "$COMPILER_VERSION" ]; then
48+
errMsg="❌ Compiler version mismatch!%0AExpected: $COMPILER_VERSION%0AGot: $COMPUTED_COMPILER_VERSION"
49+
echo "::error::$errMsg"
50+
exit 1
51+
fi
52+
echo "✅ Compiler version matches: $COMPUTED_COMPILER_VERSION"
53+
54+
# Check language version using new command
55+
LANGUAGE_OUTPUT=$(compact compile --language-version)
56+
COMPUTED_LANGUAGE_VERSION=$(echo "$LANGUAGE_OUTPUT" | grep -oP '\b[0-9]+\.[0-9]+\.[0-9]+\b' | tail -n 1)
57+
if [ "$COMPUTED_LANGUAGE_VERSION" != "$LANGUAGE_VERSION" ]; then
58+
errMsg="❌ Language version mismatch!%0AExpected: $LANGUAGE_VERSION%0AGot: $COMPUTED_LANGUAGE_VERSION"
6859
echo "::error::$errMsg"
6960
exit 1
70-
fi
71-
echo "✅ Compiler version matches: $COMPUTED_COMPILER_VERSION"
72-
73-
LANGUAGE_OUTPUT=$(compactc --language-version)
74-
COMPUTED_LANGUAGE_VERSION=$(echo "$LANGUAGE_OUTPUT" | grep -oP '\b0\.[0-9]+\.[0-9]+\b' | tail -n 1)
75-
if [ "$COMPUTED_LANGUAGE_VERSION" != "$LANGUAGE_VERSION" ]; then
76-
errMsg="❌ Language version mismatch!%0AExpected: $LANGUAGE_VERSION%0AGot: $COMPUTED_LANGUAGE_VERSION"
77-
echo "::error::$errMsg"
78-
exit 1
79-
fi
80-
81-
echo "✅ Language version matches: $COMPUTED_LANGUAGE_VERSION"
61+
fi
62+
echo "✅ Language version matches: $COMPUTED_LANGUAGE_VERSION"
8263
8364
- name: Compile contracts (with retry on hash mismatch)
8465
shell: bash
8566
run: |
86-
set -euo pipefail
87-
8867
compile() {
89-
echo "⚙️ Running Compact compilation..."
9068
if ! output=$(turbo compact --concurrency=1 2>&1); then
91-
echo "❌ Compilation failed."
9269
if echo "$output" | grep -q "Hash mismatch" && [ -d "$HOME/.cache/midnight/zk-params" ]; then
93-
echo "⚠️ Hash mismatch detected *and* zk-params exists. Removing cache..."
70+
echo "Hash mismatch detected. Clearing zk-params cache..."
9471
rm -rf "$HOME/.cache/midnight/zk-params"
95-
echo "::notice::♻️ Retrying compilation after clearing zk-params..."
96-
turbo compact --concurrency=1 || { echo "::error::❌ Retry also failed."; exit 1; }
72+
echo "Retrying compilation..."
73+
turbo compact --concurrency=1
9774
else
98-
echo "🚫 Compilation failed for another reason or zk-params missing. No retry."
75+
echo "$output"
9976
exit 1
10077
fi
10178
fi
10279
}
103-
10480
compile
10581
10682
- name: Run type checks

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515

1616
Make sure you have [nvm](https://github.com/nvm-sh/nvm), [yarn](https://yarnpkg.com/getting-started/install), and [turbo](https://turborepo.com/docs/getting-started/installation) installed on your machine.
1717

18-
Follow Midnight's [compact installation guide](https://docs.midnight.network/develop/tutorial/building/#midnight-compact-compiler) and confirm that `compactc` is in the `PATH` env variable.
18+
Follow Midnight's [Compact Developer Tools installation guide](https://docs.midnight.network/develop/tutorial/building/#midnight-compact-compiler) and confirm that `compact` is in the `PATH` env variable.
1919

2020
```bash
21-
$ compactc
21+
$ compact compile --version
2222

2323
Compactc version: 0.24.0
24-
Usage: compactc.bin <flag> ... <source-pathname> <target-directory-pathname>
25-
--help displays detailed usage information
24+
0.24.0
2625
```
2726

2827
## Set up the project
@@ -32,7 +31,7 @@ Usage: compactc.bin <flag> ... <source-pathname> <target-directory-pathname>
3231
> - [node](https://nodejs.org/)
3332
> - [yarn](https://yarnpkg.com/getting-started/install)
3433
> - [turbo](https://turborepo.com/docs/getting-started/installation)
35-
> - [compact](https://docs.midnight.network/develop/tutorial/building/#midnight-compact-compiler)
34+
> - [compact](https://docs.midnight.network/blog/compact-developer-tools)
3635
3736
Clone the repository:
3837

compact/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
"scripts": {
2323
"build": "tsc -p .",
2424
"types": "tsc -p tsconfig.json --noEmit",
25+
"test": "yarn vitest run",
2526
"clean": "git clean -fXd"
2627
},
2728
"devDependencies": {
2829
"@types/node": "22.14.0",
2930
"fast-check": "^3.15.0",
30-
"typescript": "^5.8.2"
31+
"typescript": "^5.8.2",
32+
"vitest": "^3.1.3"
3133
},
3234
"dependencies": {
3335
"chalk": "^5.4.1",

0 commit comments

Comments
 (0)