Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install Zig
uses: mlugg/setup-zig@8d6198c65fb0feaa111df26e6b467fea8345e46f # ratchet:mlugg/setup-zig@v2.0.5
with:
version: 0.15.2
version: 0.16.0

- name: Install expect (Ubuntu)
if: startsWith(matrix.os, 'ubuntu-')
Expand All @@ -50,4 +50,4 @@ jobs:
uses: roc-lang/roc/.github/actions/flaky-retry@main
with:
command: ./ci/all_tests.sh
error_string_contains: "error: unable"
error_string_contains: "error: (unable|invalid HTTP response)|HttpConnectionClosing"
34 changes: 5 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,15 @@ jobs:
- name: Install Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Install Rust with cross-compilation targets
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-apple-darwin,aarch64-apple-darwin,x86_64-unknown-linux-musl,aarch64-unknown-linux-musl

- name: Build Roc from pinned commit
run: |
echo "Building roc from pinned commit..."
ROC_COMMIT=$(python3 ci/get_roc_commit.py)

git init roc-src
cd roc-src
git remote add origin https://github.com/roc-lang/roc
git fetch --depth 1 origin "$ROC_COMMIT"
git checkout --detach "$ROC_COMMIT"

zig build roc

echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
run: ./ci/build_pinned_roc.sh

- name: Build platform for all targets
run: ./build.sh --all
Expand Down Expand Up @@ -111,7 +99,7 @@ jobs:
- name: Install Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
version: 0.16.0

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
Expand All @@ -125,19 +113,7 @@ jobs:
run: brew install expect

- name: Build Roc from pinned commit
run: |
echo "Building roc from pinned commit..."
ROC_COMMIT=$(python3 ci/get_roc_commit.py)

git init roc-src
cd roc-src
git remote add origin https://github.com/roc-lang/roc
git fetch --depth 1 origin "$ROC_COMMIT"
git checkout --detach "$ROC_COMMIT"

zig build roc

echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
run: ./ci/build_pinned_roc.sh

- name: Download bundle artifact
uses: actions/download-artifact@v4
Expand Down Expand Up @@ -179,7 +155,7 @@ jobs:
uses: roc-lang/roc/.github/actions/flaky-retry@main
with:
command: bash ci/all_tests.sh
error_string_contains: "error: unable"
error_string_contains: "error: (unable|invalid HTTP response)|HttpConnectionClosing"
env:
# Skip native build and rebundling since examples already point at the
# downloaded bundle served by the previous step.
Expand Down
2 changes: 1 addition & 1 deletion .roc-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34fe463f45e994b33621578298d1112a764a245b
1fc827d1e5867221c344bcd3f57a72e1929bae75
14 changes: 2 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The pinned Roc compiler commit lives in `.roc-version`. To update it:

1. Update `.roc-version` to the full 40-character Roc commit SHA.
2. Run `./ci/regenerate_glue.sh` to refresh `src/roc_platform_abi.rs`.
3. Run `cargo check --workspace` and `./ci/all_tests.sh` to verify the new compiler works.
3. Run `cargo check` and `./ci/all_tests.sh` to verify the new compiler works.

## How to generate docs?

Expand All @@ -27,7 +27,7 @@ When the platform API changes in `platform/*.roc`, regenerate the Rust ABI bindi
The script writes `src/roc_platform_abi.rs` using Roc's `RustGlue.roc` generator. It defaults to a sibling `../roc` checkout, and you can override paths when needed:

```bash
ROC=/path/to/roc/zig-out/bin/roc ROC_SRC=/path/to/roc ./ci/regenerate_glue.sh
ROC=../roc/zig-out/bin/roc ROC_SRC=../roc ./ci/regenerate_glue.sh
```

To verify the checked-in glue is current without modifying the worktree:
Expand All @@ -38,14 +38,4 @@ To verify the checked-in glue is current without modifying the worktree:

Commit the platform API change, the regenerated `src/roc_platform_abi.rs`, and any required Rust host implementation updates together. Do not edit the generated glue file manually.

## Updating Roc

The pinned Roc compiler commit lives in `.roc-version`. After changing it, run:

```bash
./ci/regenerate_glue.sh
cargo check --workspace
./build.sh
```

Run `./ci/all_tests.sh` before opening a release or CI-facing PR.
35 changes: 18 additions & 17 deletions ci/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,7 @@ if [ "$NEED_BUILD" = true ] && [ -d "roc-src" ] && [ -f "roc-src/zig-out/bin/roc
fi

if [ "$NEED_BUILD" = true ]; then
echo "Building roc from pinned commit $ROC_COMMIT..."

rm -rf roc-src
git init roc-src
cd roc-src
git remote add origin https://github.com/roc-lang/roc
git fetch --depth 1 origin "$ROC_COMMIT"
git checkout --detach "$ROC_COMMIT"

zig build roc

# Add to GITHUB_PATH if running in CI
if [ -n "${GITHUB_PATH:-}" ]; then
echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
fi

cd ..
ROC_COMMIT="$ROC_COMMIT" ./ci/build_pinned_roc.sh
USE_ROC_SRC=true
fi

Expand Down Expand Up @@ -134,11 +118,16 @@ MIGRATED_EXAMPLES=(
"random"
"locale"
"tty"
"dir"
"env-var"
)

EXAMPLES_DIR="${ROOT_DIR}/examples/"
export EXAMPLES_DIR

TESTS_DIR="${ROOT_DIR}/tests/"
export TESTS_DIR

# Check if all target libraries exist for bundling
ALL_TARGETS_EXIST=true
for target in x64mac arm64mac x64musl arm64musl; do
Expand Down Expand Up @@ -207,6 +196,18 @@ for example in "${MIGRATED_EXAMPLES[@]}"; do
roc check "examples/${example}.roc"
done

TESTS_FILES=()
for roc_file in "${TESTS_DIR}"*.roc; do
[ -f "$roc_file" ] && TESTS_FILES+=("$(basename "${roc_file%.roc}")")
done

echo ""
echo "=== Checking tests ==="
for test in "${TESTS_FILES[@]}"; do
echo "Checking: ${test}.roc"
roc check "tests/${test}.roc"
done

# roc build migrated examples
echo ""
if [ "$USE_BUNDLE" = true ]; then
Expand Down
55 changes: 55 additions & 0 deletions ci/build_pinned_roc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"

ROC_COMMIT="${ROC_COMMIT:-$(python3 ci/get_roc_commit.py)}"
MAX_ATTEMPTS="${ROC_BUILD_RETRY_COUNT:-4}"
TRANSIENT_BUILD_ERROR='error: (unable|invalid HTTP response)|HttpConnectionClosing'

echo "Building roc from pinned commit $ROC_COMMIT..."

rm -rf roc-src
git init roc-src
cd roc-src
git remote add origin https://github.com/roc-lang/roc
git fetch --depth 1 origin "$ROC_COMMIT"
git checkout --detach "$ROC_COMMIT"

attempt=1
while [ "$attempt" -le "$MAX_ATTEMPTS" ]; do
echo "Building roc attempt $attempt of $MAX_ATTEMPTS"
output_file="$(mktemp)"

set +e
zig build roc > "$output_file" 2>&1
status=$?
set -e

cat "$output_file"

if [ "$status" -eq 0 ]; then
rm -f "$output_file"
break
fi

if [ "$attempt" -ge "$MAX_ATTEMPTS" ]; then
rm -f "$output_file"
exit "$status"
fi

if grep -Eq "$TRANSIENT_BUILD_ERROR" "$output_file"; then
echo "Transient roc build failure; retrying..."
rm -f "$output_file"
attempt=$((attempt + 1))
sleep 2
else
rm -f "$output_file"
exit "$status"
fi
done

if [ -n "${GITHUB_PATH:-}" ]; then
echo "$(pwd)/zig-out/bin" >> "$GITHUB_PATH"
fi
27 changes: 16 additions & 11 deletions ci/expect_scripts/command.exp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ source ./ci/expect_scripts/shared-code.exp

spawn $env(EXAMPLES_DIR)command

expect "Hello"
expect "{stderr_utf8_lossy: \"\", stdout_utf8: \"Hi"
expect "\"}"
expect "BAZ=DUCK"
expect "FOO=BAR"
expect "XYZ=ABC"
expect "cat: non_existent.txt: No such file or directory"
expect "Exit code: 1"
set expected_output [normalize_output {
Hello
{ stderr_utf8_lossy: "", stdout_utf8: "Hi
" }
BAZ=DUCK
FOO=BAR
XYZ=ABC
cat: non_existent.txt: No such file or directory
Exit code: 1
{ stderr_bytes: [], stdout_bytes: [72, 105, 10] }
}]

expect eof {
check_exit_and_segfault
expect -exact $expected_output {
expect eof {
check_exit_and_segfault
}
}

puts stderr "\nExpect script failed: output was not as expected. Diff the output with expected_output in this script. Alternatively, uncomment `exp_internal 1` to debug."
exit 1
exit 1
2 changes: 0 additions & 2 deletions ci/expect_scripts/env-var.exp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ set timeout 7
source ./ci/expect_scripts/shared-code.exp

set env(EDITOR) nano
set env(LETTERS) a,c,e,j

spawn $env(EXAMPLES_DIR)env-var


set expected_output [normalize_output {
Your favorite editor is nano!
Your favorite letters are: a c e j
}]

expect $expected_output {
Expand Down
10 changes: 6 additions & 4 deletions ci/regenerate_glue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"

ROC_BIN="${ROC:-roc}"
PLATFORM_FILE="${PLATFORM_FILE:-$ROOT_DIR/platform/main.roc}"
GLUE_OUT_DIR="${GLUE_OUT_DIR:-$ROOT_DIR/src}"
PLATFORM_FILE="${PLATFORM_FILE:-platform/main.roc}"
GLUE_OUT_DIR="${GLUE_OUT_DIR:-src}"
MODE="write"

usage() {
Expand Down Expand Up @@ -66,8 +68,8 @@ find_glue_spec() {
fi

candidates+=(
"$ROOT_DIR/../roc/src/glue/src/RustGlue.roc"
"$ROOT_DIR/../../roc/src/glue/src/RustGlue.roc"
"../roc/src/glue/src/RustGlue.roc"
"../../roc/src/glue/src/RustGlue.roc"
)

for candidate in "${candidates[@]}"; do
Expand Down
7 changes: 3 additions & 4 deletions examples/bytes-stdin-stdout.roc
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ app [main!] { pf: platform "../platform/main.roc" }
import pf.Stdin
import pf.Stdout
import pf.Stderr
import pf.Arg exposing [Arg]

# To run this example: check the README.md in this folder

main! : List Arg => Result {} _
main! = |_args|
main! = |_args| {
data = Stdin.bytes!({})?
Stderr.write_bytes!(data)?
Stdout.write_bytes!(data)?
Ok {}
Ok({})
}
5 changes: 2 additions & 3 deletions examples/command-line-args.roc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ app [main!] { pf: platform "../platform/main.roc" }

import pf.Stdout

main! : List(Str) => Try({}, [Exit(I32)])
main! = |args| {
# Skip first arg (executable path), get the remaining args
match args.drop_first(1) {
[first_arg, ..] => {
Stdout.line!("received argument: ${first_arg}")
_ = Stdout.line!("received argument: ${first_arg}")
Ok({})
}
[] => {
Stdout.line!("Error: I expected one argument, but got none.")
_ = Stdout.line!("Error: I expected one argument, but got none.")
Err(Exit(1))
}
}
Expand Down
Loading
Loading