Skip to content

Commit

Permalink
Merge branch 'main' into proposed-ir
Browse files Browse the repository at this point in the history
  • Loading branch information
smores56 committed Feb 6, 2025
2 parents 5a4095a + 25b076b commit 261876f
Show file tree
Hide file tree
Showing 54 changed files with 1,472 additions and 242 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly_macos_apple_silicon.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on:
# pull_request:
# pull_request:
workflow_dispatch:
schedule:
- cron: "0 9 * * *"
Expand Down Expand Up @@ -58,7 +58,7 @@ jobs:

- name: test with zig platform
run: |
cd ${{ env.RELEASE_FOLDER_NAME }} && ./roc --build-host --suppress-build-host-warning examples/platform-switching/rocLovesZig.roc
cd ${{ env.RELEASE_FOLDER_NAME }} && ./roc --build-host --suppress-build-host-warning examples/platform-switching/roc_loves_zig.roc
- name: print short commit SHA
run: git rev-parse --short "$GITHUB_SHA"
Expand Down
27 changes: 10 additions & 17 deletions BUILDING_FROM_SOURCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Or even run it in your local Docker environment [Developing inside a Container](

## Using Nix

On MacOS and Linux, we highly recommend Using [nix](https://nixos.org/download.html) to quickly install all dependencies necessary to build roc.
On MacOS and Linux, we highly recommend using [nix](https://nixos.org/download.html) to quickly install all dependencies necessary to build roc.

:warning: If you tried to run `cargo` in the repo folder before installing nix, make sure to execute `cargo clean` first. To prevent you from executing `cargo` outside of nix, tools like [direnv](https://github.com/nix-community/nix-direnv) and [lorri](https://github.com/nix-community/lorri) can put you in a nix shell automatically when you `cd` into the directory.

Expand Down Expand Up @@ -89,22 +89,6 @@ Alternatively, you can use `cargo test --no-fail-fast` or `cargo test -p specifi

For emitting LLVM IR for debugging purposes, the `--emit-llvm-ir` flag can be used.

### libxcb libraries

You may see an error like this during builds:

```text
/usr/bin/ld: cannot find -lxcb-render
/usr/bin/ld: cannot find -lxcb-shape
/usr/bin/ld: cannot find -lxcb-xfixes
```

If so, you can fix it like so:

```sh
sudo apt-get install libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev
```

### libz libzstd libraries

You may see an error like this during builds:
Expand All @@ -120,6 +104,15 @@ If so, you can fix it like so:
sudo apt-get install libz-dev libzstd-dev
```

#### Macos zstd not found

If you still hit `ld: library 'zstd' not found` even after doing `brew install zstd z3`,
add these lines to `.cargo/config.toml`:
```
[target.aarch64-apple-darwin]
rustflags = ["-C", "link-args=-L/opt/homebrew/lib"]
```

### Zig

**version: 0.13.0**
Expand Down
5 changes: 5 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Zig unicode library - https://codeberg.org/atman/zg
const zg = b.dependency("zg", .{});

const exe = b.addExecutable(.{
.name = "roc",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("GenCatData", zg.module("GenCatData"));

b.installArtifact(exe);

Expand All @@ -34,6 +38,7 @@ pub fn build(b: *std.Build) void {
.target = target,
.optimize = optimize,
});
all_tests.root_module.addImport("GenCatData", zg.module("GenCatData"));

// Install the test binary so we can run separately
// ```sh
Expand Down
4 changes: 4 additions & 0 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
.url = "git+https://github.com/kristoff-it/zig-afl-kit#88c6b71377767c1b8d26979b0adfa12a58d988dd",
.hash = "1220796f7d2d9a2d4d7f8339ee0b14aa4bf133a15ae9ba39c941cc68e08d5c5ce9a2",
},
.zg = .{
.url = "https://codeberg.org/dude_the_builder/zg/archive/v0.13.2.tar.gz",
.hash = "122055beff332830a391e9895c044d33b15ea21063779557024b46169fb1984c6e40",
},
},
.paths = .{
"build.zig",
Expand Down
6 changes: 3 additions & 3 deletions ci/basic_release_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ cd roc_release/*/
# test rust platform (first prebuild the host)
# temp disabled
# examples/platform-switching/rust-platform/build.sh
# ./roc examples/platform-switching/rocLovesRust.roc
# ./roc examples/platform-switching/roc_loves_rust.roc

# test zig platform
./roc --build-host --suppress-build-host-warning examples/platform-switching/rocLovesZig.roc
./roc --build-host --suppress-build-host-warning examples/platform-switching/roc_loves_zig.roc

# test C platform
./roc --build-host --suppress-build-host-warning examples/platform-switching/rocLovesC.roc
./roc --build-host --suppress-build-host-warning examples/platform-switching/roc_loves_c.roc

# test repl
cd ../../ci/repl_basic_test
Expand Down
2 changes: 1 addition & 1 deletion ci/package_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mv crates/cli/tests/platform-switching $1/examples
mv examples/README.md $1/examples

# temporary github.com/roc-lang/roc/pull/7231
rm $1/examples/platform-switching/rocLovesRust.roc
rm $1/examples/platform-switching/roc_loves_rust.roc
rm -rf $1/examples/platform-switching/rust-platform

# copy zig builtins
Expand Down
18 changes: 9 additions & 9 deletions crates/cli/tests/benchmarks/AStar.roc
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ astar = \cost_fn, move_fn, goal, model ->

astar(cost_fn, move_fn, goal, model_with_costs)

# takeStep = \moveFn, _goal, model, current ->
# modelPopped =
# take_step = \move_fn, _goal, model, current ->
# model_popped =
# { model &
# openSet: Set.remove model.openSet current,
# open_set: Set.remove model.open_set current,
# evaluated: Set.insert model.evaluated current,
# }
#
# neighbors = moveFn current
# neighbors = move_fn current
#
# newNeighbors = Set.difference neighbors modelPopped.evaluated
# new_neighbors = Set.difference neighbors model_popped.evaluated
#
# modelWithNeighbors = { modelPopped & openSet: Set.union modelPopped.openSet newNeighbors }
# model_with_neighbors = { model_popped & open_set: Set.union model_popped.open_set new_neighbors }
#
# # a lot goes wrong here
# modelWithCosts =
# Set.walk newNeighbors modelWithNeighbors (\n, m -> updateCost current n m)
# model_with_costs =
# Set.walk new_neighbors model_with_neighbors (\n, m -> update_cost current n m)
#
# modelWithCosts
# model_with_costs
2 changes: 1 addition & 1 deletion crates/cli/tests/benchmarks/Base64/Decode.roc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ lowest6_bits_mask = 63
bits_to_chars_help : U32, Int * -> List U8
bits_to_chars_help = \bits, missing ->
# The input is 24 bits, which we have to partition into 4 6-bit segments. We achieve this by
# shifting to the right by (a multiple of) 6 to remove unwanted bits on the right, then `Num.bitwiseAnd`
# shifting to the right by (a multiple of) 6 to remove unwanted bits on the right, then `Num.bitwise_and`
# with `0b111111` (which is 2^6 - 1 or 63) (so, 6 1s) to remove unwanted bits on the left.
# any 6-bit number is a valid base64 digit, so this is actually safe
p =
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/benchmarks/Base64/Encode.roc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ folder = \{ output, accum }, char ->
{ output, accum: None }

# SGVs bG8g V29y bGQ=
# encodeResidual : { output : List ByteEncoder, accum : State } -> List ByteEncoder
# encode_residual : { output : List ByteEncoder, accum : State } -> List ByteEncoder
encode_residual = \{ output, accum } ->
when accum is
Unreachable(_) -> output
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 25 additions & 20 deletions crates/cli/tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod cli_tests {

let cli_build = ExecCli::new(
roc_cli::CMD_DEV,
file_from_root("crates/cli/tests/platform-switching", "rocLovesRust.roc"),
file_from_root("crates/cli/tests/platform-switching", "roc_loves_rust.roc"),
);

let expected_output = "Roc <3 Rust!\n";
Expand All @@ -80,7 +80,7 @@ mod cli_tests {

let cli_build = ExecCli::new(
CMD_BUILD,
file_from_root("crates/cli/tests/platform-switching", "rocLovesZig.roc"),
file_from_root("crates/cli/tests/platform-switching", "roc_loves_zig.roc"),
)
.arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG);
Expand All @@ -106,7 +106,7 @@ mod cli_tests {
CMD_CHECK,
file_from_root(
"crates/cli/tests/platform-switching",
"rocLovesWebAssembly.roc",
"roc_loves_web_assembly.roc",
),
);

Expand Down Expand Up @@ -382,7 +382,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/effectful",
"combine-tasks.roc",
"combine_tasks.roc",
),
);

Expand Down Expand Up @@ -605,7 +605,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/fixtures/transitive-deps",
"direct-one.roc",
"direct_one.roc",
),
);

Expand All @@ -629,7 +629,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/fixtures/transitive-deps",
"direct-one-and-two.roc",
"direct_one_and_two.roc",
),
);

Expand All @@ -653,7 +653,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/fixtures/transitive-deps",
"direct-zero.roc",
"direct_zero.roc",
),
);

Expand Down Expand Up @@ -815,7 +815,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/test-platform-effects-zig/",
"app-stub.roc",
"app_stub.roc",
),
)
.arg(BUILD_HOST_FLAG)
Expand All @@ -841,7 +841,7 @@ mod cli_tests {

let cli_build = ExecCli::new(
CMD_BUILD,
file_from_root("crates/cli/tests/test-projects/effectful", "print-line.roc"),
file_from_root("crates/cli/tests/test-projects/effectful", "print_line.roc"),
);

let expected_output =
Expand All @@ -865,7 +865,7 @@ mod cli_tests {
CMD_BUILD,
file_from_root(
"crates/cli/tests/test-projects/effectful",
"inspect-logging.roc",
"inspect_logging.roc",
),
);

Expand Down Expand Up @@ -1202,7 +1202,7 @@ mod cli_tests {
Please enter an integer
4
"};
test_benchmark("nQueens.roc", expected_output, Some("6"), UseValgrind::Yes);
test_benchmark("n_queens.roc", expected_output, Some("6"), UseValgrind::Yes);
}

#[test]
Expand All @@ -1212,7 +1212,7 @@ mod cli_tests {
Please enter an integer
11 & 11
"};
test_benchmark("cFold.roc", expected_output, Some("3"), UseValgrind::Yes);
test_benchmark("c_fold.roc", expected_output, Some("3"), UseValgrind::Yes);
}

#[test]
Expand All @@ -1234,7 +1234,7 @@ mod cli_tests {
10
"};
test_benchmark(
"rBTreeCk.roc",
"r_b_tree_ck.roc",
expected_output,
Some("100"),
UseValgrind::Yes,
Expand All @@ -1245,17 +1245,22 @@ mod cli_tests {
#[cfg_attr(windows, ignore)]
fn rbtree_insert() {
let expected_output = "Node Black 0 {} Empty Empty\n";
test_benchmark("rBTreeInsert.roc", expected_output, None, UseValgrind::Yes);
test_benchmark(
"r_b_tree_insert.roc",
expected_output,
None,
UseValgrind::Yes,
);
}

#[test]
#[cfg_attr(windows, ignore)]
fn astar() {
if cfg!(feature = "wasm32-cli-run") {
eprintln!("WARNING: skipping testing benchmark testAStar.roc because it currently does not work on wasm32 due to dictionaries.");
eprintln!("WARNING: skipping testing benchmark test_a_star.roc because it currently does not work on wasm32 due to dictionaries.");
} else {
let expected_output = "True\n";
test_benchmark("testAStar.roc", expected_output, None, UseValgrind::Yes);
test_benchmark("test_a_star.roc", expected_output, None, UseValgrind::Yes);
}
}

Expand All @@ -1266,7 +1271,7 @@ mod cli_tests {
encoded: SGVsbG8gV29ybGQ=
decoded: Hello World
"};
test_benchmark("testBase64.roc", expected_output, None, UseValgrind::Yes);
test_benchmark("test_base64.roc", expected_output, None, UseValgrind::Yes);
}

#[test]
Expand All @@ -1288,7 +1293,7 @@ mod cli_tests {
fn quicksort_app() {
let expected_output = "Please enter an integer\n[0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6, 8, 9]\n";
test_benchmark(
"quicksortApp.roc",
"quicksort_app.roc",
expected_output,
Some("0"),
UseValgrind::Yes,
Expand Down Expand Up @@ -1423,7 +1428,7 @@ mod cli_tests {
CMD_FORMAT,
file_from_root(
"crates/cli/tests/test-projects/fixtures/format",
"not-formatted.roc",
"not_formatted.roc",
),
)
.arg(CHECK_FLAG)
Expand All @@ -1433,7 +1438,7 @@ mod cli_tests {

#[test]
fn format_check_folders() {
// This fails, because "not-formatted.roc" is present in this folder
// This fails, because "not_formatted.roc" is present in this folder
ExecCli::new(
CMD_FORMAT,
dir_from_root("crates/cli/tests/test-projects/fixtures/format"),
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/platform-switching/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
To run, `cd` into this directory and run this in your terminal:

```bash
roc --build-host --suppress-build-host-warning rocLovesC.roc
roc --build-host --suppress-build-host-warning roc_loves_c.roc
```

## About these examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ app [main] { pf: platform "c-platform/main.roc" }
# ubuntu: sudo apt install build-essential clang
# fedora: sudo dnf install clang

# run with `roc --build-host --suppress-build-host-warning rocLovesC.roc`
# run with `roc --build-host --suppress-build-host-warning roc_loves_c.roc`

main = "Roc <3 C!\n"
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ app [main] { pf: platform "zig-platform/main.roc" }
# mkdir glue
# cp crates/compiler/builtins/bitcode/src/* ./glue
# cd -
# roc --build-host --suppress-build-host-warning rocLovesZig.roc
# roc --build-host --suppress-build-host-warning roc_loves_zig.roc

main = "Roc <3 Zig!\n"
Loading

0 comments on commit 261876f

Please sign in to comment.