Skip to content

Commit 8c951de

Browse files
fix some things
1 parent 953ed5f commit 8c951de

File tree

13 files changed

+477
-416
lines changed

13 files changed

+477
-416
lines changed

.github/workflows/release.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release_tag:
7+
description: 'Release tag (e.g., v0.1.0)'
8+
required: true
9+
type: string
10+
pull_request:
11+
12+
# Ensure only one release workflow runs at a time
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build-and-bundle:
19+
name: Build and Bundle Platform
20+
runs-on: macos-15 # macOS can cross-compile to all targets
21+
outputs:
22+
bundle_filename: ${{ steps.bundle.outputs.bundle_filename }}
23+
defaults:
24+
run:
25+
shell: bash
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Install Zig
32+
uses: mlugg/setup-zig@v2
33+
with:
34+
version: 0.15.2
35+
36+
- name: Install Rust with cross-compilation targets
37+
uses: dtolnay/rust-toolchain@stable
38+
with:
39+
targets: x86_64-apple-darwin,aarch64-apple-darwin,x86_64-unknown-linux-musl,aarch64-unknown-linux-musl
40+
41+
- name: Build Roc from pinned commit
42+
run: |
43+
echo "Building roc from pinned commit..."
44+
ROC_COMMIT=$(python3 ci/get_roc_commit.py)
45+
46+
git init roc-src
47+
cd roc-src
48+
git remote add origin https://github.com/roc-lang/roc
49+
git fetch --depth 1 origin "$ROC_COMMIT"
50+
git checkout --detach "$ROC_COMMIT"
51+
52+
zig build roc
53+
54+
echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
55+
56+
- name: Build platform for all targets
57+
run: ./build.sh --all
58+
59+
- name: Bundle platform
60+
id: bundle
61+
run: |
62+
# Run bundle.sh and capture output
63+
BUNDLE_OUTPUT=$(./bundle.sh 2>&1)
64+
echo "$BUNDLE_OUTPUT"
65+
66+
# Extract the tar.zst filename from "Created: /path/to/HASH.tar.zst" line
67+
BUNDLE_PATH=$(echo "$BUNDLE_OUTPUT" | grep "^Created:" | awk '{print $2}')
68+
BUNDLE_FILENAME=$(basename "$BUNDLE_PATH")
69+
70+
if [ -z "$BUNDLE_FILENAME" ]; then
71+
echo "Error: Could not extract bundle filename from output"
72+
echo "Bundle output was:"
73+
echo "$BUNDLE_OUTPUT"
74+
exit 1
75+
fi
76+
77+
echo "Bundle created: $BUNDLE_FILENAME"
78+
echo "bundle_filename=$BUNDLE_FILENAME" >> "$GITHUB_OUTPUT"
79+
80+
- name: Upload bundle artifact
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: platform-bundle
84+
path: ${{ steps.bundle.outputs.bundle_filename }}
85+
retention-days: 30
86+
87+
test-bundle:
88+
name: Test Bundle (${{ matrix.os }})
89+
needs: build-and-bundle
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
os:
94+
- macos-15 # Apple Silicon
95+
- macos-15-intel # Intel Mac
96+
- ubuntu-22.04 # Linux x86_64
97+
- ubuntu-24.04-arm # Linux ARM64
98+
runs-on: ${{ matrix.os }}
99+
defaults:
100+
run:
101+
shell: bash
102+
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v4
106+
107+
- name: Install Zig
108+
uses: mlugg/setup-zig@v2
109+
with:
110+
version: 0.15.2
111+
112+
- name: Install Rust
113+
uses: dtolnay/rust-toolchain@stable
114+
115+
- name: Install expect (Ubuntu)
116+
if: startsWith(matrix.os, 'ubuntu-')
117+
run: sudo apt-get install -y expect
118+
119+
- name: Install expect (macOS)
120+
if: startsWith(matrix.os, 'macos-')
121+
run: brew install expect
122+
123+
- name: Build Roc from pinned commit
124+
run: |
125+
echo "Building roc from pinned commit..."
126+
ROC_COMMIT=$(python3 ci/get_roc_commit.py)
127+
128+
git init roc-src
129+
cd roc-src
130+
git remote add origin https://github.com/roc-lang/roc
131+
git fetch --depth 1 origin "$ROC_COMMIT"
132+
git checkout --detach "$ROC_COMMIT"
133+
134+
zig build roc
135+
136+
echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
137+
138+
- name: Download bundle artifact
139+
uses: actions/download-artifact@v4
140+
with:
141+
name: platform-bundle
142+
143+
- name: Start HTTP server for bundle
144+
run: |
145+
# Start Python HTTP server in background on port 8000
146+
python3 -m http.server 8000 &
147+
HTTP_SERVER_PID=$!
148+
echo "HTTP_SERVER_PID=$HTTP_SERVER_PID" >> "$GITHUB_ENV"
149+
150+
# Wait for server to start
151+
sleep 5
152+
153+
# Verify server is running and bundle is accessible
154+
if ! curl -f -I "http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}" > /dev/null 2>&1; then
155+
echo "Error: HTTP server not accessible or bundle not found"
156+
kill $HTTP_SERVER_PID || true
157+
exit 1
158+
fi
159+
160+
echo "HTTP server started on port 8000 (PID: $HTTP_SERVER_PID)"
161+
echo "Bundle accessible at: http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}"
162+
163+
- name: Modify examples to use bundled platform
164+
run: |
165+
# Replace local platform path with HTTP URL in all examples
166+
for example in examples/*.roc; do
167+
sed -i.bak "s|platform \"../platform/main.roc\"|platform \"http://localhost:8000/${{ needs.build-and-bundle.outputs.bundle_filename }}\"|g" "$example"
168+
done
169+
170+
# Show diff for verification
171+
echo "Modified examples:"
172+
git diff examples/ | head -50
173+
174+
- name: Run tests with bundled platform
175+
run: |
176+
# Skip native build since we're using the bundle
177+
# The test script will detect all targets exist and use bundle testing
178+
export NO_BUILD=1
179+
180+
# Run all tests against the bundled platform
181+
bash ci/all_tests.sh
182+
183+
create-release:
184+
name: Create GitHub Release
185+
needs: [build-and-bundle, test-bundle]
186+
runs-on: ubuntu-24.04
187+
# Only run on manual trigger
188+
if: github.event_name == 'workflow_dispatch'
189+
permissions:
190+
contents: write
191+
192+
steps:
193+
- name: Checkout
194+
uses: actions/checkout@v4
195+
196+
- name: Download bundle artifact
197+
uses: actions/download-artifact@v4
198+
with:
199+
name: platform-bundle
200+
201+
- name: Create GitHub Release
202+
env:
203+
GH_TOKEN: ${{ github.token }}
204+
run: |
205+
BUNDLE_FILE=$(ls *.tar.zst | head -1)
206+
207+
if [ -z "$BUNDLE_FILE" ]; then
208+
echo "Error: No bundle file found"
209+
exit 1
210+
fi
211+
212+
ROC_COMMIT=$(python3 ci/get_roc_commit.py | cut -c1-8)
213+
214+
# Create release with auto-generated notes
215+
gh release create "${{ github.event.inputs.release_tag }}" \
216+
"$BUNDLE_FILE" \
217+
--title "${{ github.event.inputs.release_tag }}" \
218+
--generate-notes \
219+
--notes "Platform bundle built with Rust (stable) and Roc $ROC_COMMIT"
220+
221+
echo "Release created: ${{ github.event.inputs.release_tag }}"
222+
echo "Bundle uploaded: $BUNDLE_FILE"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ platform/targets/*/libhost.a
8484

8585
# Cargo lock for reproducible builds
8686
!Cargo.lock
87+
88+
# Bundled platform package
89+
*.tar.zst

CONTRIBUTING.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,4 @@ We are committed to providing a friendly, safe and welcoming environment for all
66

77
## How to generate docs?
88

9-
You can generate the documentation locally and then start a web server to host your files.
10-
11-
```bash
12-
roc docs platform/main.roc
13-
cd generated-docs
14-
simple-http-server --nocache --index # comes pre-installed if you use `nix develop`, otherwise use `cargo install simple-http-server`.
15-
```
16-
17-
Open http://0.0.0.0:8000 in your browser
9+
TODO describe how to generate docs once `roc docs` is implemented in the new compiler

Cargo.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ roc_std_new.workspace = true
1616
roc_io_error.workspace = true
1717
roc_random.workspace = true
1818
roc_command.workspace = true
19+
memoffset = "0.9.1"
1920

2021
[workspace]
2122
members = [
@@ -33,7 +34,7 @@ repository = "https://github.com/roc-lang/basic-cli"
3334

3435
[workspace.dependencies]
3536
# Core Roc types
36-
roc_std_new = { git = "https://github.com/roc-lang/roc", rev = "8753d9a30189d878b54d2a4981becf88ad4bbb1a" }
37+
roc_std_new = { git = "https://github.com/roc-lang/roc", rev = "386a79b49fd6d46075bf5bb562e57062e6a53c79" }
3738

3839
# Internal crates
3940
roc_io_error = { path = "crates/roc_io_error" }

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,39 @@
88
A Roc [platform](https://github.com/roc-lang/roc/wiki/Roc-concepts-explained#platform) to work with files, commands, HTTP, TCP, command line arguments,...
99

1010
:eyes: **examples**:
11-
- [0.20.0](https://github.com/roc-lang/basic-cli/tree/0.20.0/examples)
12-
- [0.19.0](https://github.com/roc-lang/basic-cli/tree/0.19.0/examples)
13-
- [0.18.0](https://github.com/roc-lang/basic-cli/tree/0.18.0/examples)
1411
- [latest main branch](https://github.com/roc-lang/basic-cli/tree/main/examples)
1512

1613
:book: **documentation**:
17-
- [0.20.0](https://roc-lang.github.io/basic-cli/0.20.0/)
18-
- [0.19.0](https://roc-lang.github.io/basic-cli/0.19.0/)
19-
- [0.18.0](https://roc-lang.github.io/basic-cli/0.18.0/)
20-
- [latest main branch](https://roc-lang.github.io/basic-cli/main/)
14+
- TBA -- `roc docs` not yet implemented in the new compiler
2115

2216
## Running Locally
2317

24-
If you clone this repo instead of using the release URL you'll need to build the platform once:
25-
```sh
26-
./jump-start.sh
27-
roc build.roc --linker=legacy
18+
**⚠️ IMPORTANT**: This branch (`migrate-zig-compiler`) requires the new Roc compiler and `roc_std_new` to be at matching versions to avoid ABI layout mismatches.
19+
20+
### Version Requirements
21+
22+
The `roc_std_new` dependency version in `Cargo.toml` MUST match your local Roc compiler version:
23+
24+
```toml
25+
# In Cargo.toml, update this to match your Roc compiler commit:
26+
roc_std_new = { path = "/path/to/your/roc/crates/roc_std_new" }
27+
# OR
28+
roc_std_new = { git = "https://github.com/roc-lang/roc", rev = "YOUR_COMMIT_HASH" }
2829
```
29-
Then you can run like usual:
30+
31+
**To check your Roc compiler version:**
3032
```sh
31-
$ roc examples/hello-world.roc
32-
Hello, World!
33+
roc --version # Shows commit hash
34+
cd /path/to/roc && git log -1 --format="%H" # Full commit hash
3335
```
36+
37+
### Migration Status
38+
39+
This branch migrates basic-cli to the new Zig-based Roc compiler and RocOps ABI.
40+
41+
**✅ Completed:**
42+
- All core modules (Cmd, File, Dir, Path, Env, Random, Sleep, Utc, Stdin/Stdout/Stderr)
43+
- Single-variant tag union layout fix (RocSingleTagWrapper now correctly includes discriminant)
44+
- Comprehensive testing and verification
45+
46+
**Note:** Single-variant tag unions (e.g., `[PathErr(IOErr)]`) are represented in the Roc ABI with a discriminant byte (always 0) even though there's only one variant. The `RocSingleTagWrapper<T>` type implements this standard Roc ABI layout. This type could potentially be upstreamed to `roc_std_new` for reuse across platforms.

bundle.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
root_dir="$(cd "$(dirname "$0")" && pwd)"
5+
cd "$root_dir/platform"
6+
7+
# Collect all .roc files
8+
roc_files=(*.roc)
9+
10+
# Collect all host libraries and runtime files from targets directories
11+
lib_files=()
12+
for lib in targets/*/*.a targets/*/*.o; do
13+
if [[ -f "$lib" ]]; then
14+
lib_files+=("$lib")
15+
fi
16+
done
17+
18+
echo "Bundling ${#roc_files[@]} .roc files and ${#lib_files[@]} library files..."
19+
echo ""
20+
echo "Files to bundle:"
21+
for f in "${roc_files[@]}"; do
22+
echo " $f"
23+
done
24+
for f in "${lib_files[@]}"; do
25+
echo " $f"
26+
done
27+
echo ""
28+
29+
roc bundle "${roc_files[@]}" "${lib_files[@]}" --output-dir "$root_dir" "$@"

0 commit comments

Comments
 (0)