Move Roc CLI testing examples to crates/

This commit is contained in:
Jan Van Bruggen 2022-09-11 21:52:48 -06:00
parent 2eec200f09
commit 527f39b8f2
No known key found for this signature in database
GPG key ID: FE2A4E38E0FA6134
75 changed files with 56 additions and 49 deletions

View file

@ -57,9 +57,10 @@ members = [
"crates/wasi-libc-sys",
]
exclude = [
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
"examples",
"ci/bench-runner",
# Examples sometimes have Rust hosts in their platforms. The compiler should ignore those.
"crates/cli_testing_examples",
"examples",
# Ignore building these normally. They are only imported by tests.
# The tests will still correctly build them.
"crates/cli_utils",

View file

@ -50,7 +50,7 @@ install-zig-llvm-valgrind:
copy-dirs:
FROM +install-zig-llvm-valgrind
COPY --dir crates examples Cargo.toml Cargo.lock version.txt www ./
COPY --dir crates Cargo.toml Cargo.lock version.txt www ./
# compile everything needed for benchmarks and output a self-contained dir from which benchmarks can be run.
prep-bench-folder:
@ -60,11 +60,11 @@ prep-bench-folder:
ARG BENCH_SUFFIX=branch
RUN cargo criterion -V
RUN --mount=type=cache,target=$SCCACHE_DIR cd crates/cli && cargo criterion --no-run
RUN mkdir -p bench-folder/crates/cli_testing_examples/benchmarks
RUN mkdir -p bench-folder/crates/compiler/builtins/bitcode/src
RUN mkdir -p bench-folder/target/release/deps
RUN mkdir -p bench-folder/examples/benchmarks
RUN cp examples/benchmarks/*.roc bench-folder/examples/benchmarks/
RUN cp -r examples/benchmarks/platform bench-folder/examples/benchmarks/
RUN cp crates/cli_testing_examples/benchmarks/*.roc bench-folder/crates/cli_testing_examples/benchmarks/
RUN cp -r crates/cli_testing_examples/benchmarks/platform bench-folder/crates/cli_testing_examples/benchmarks/
RUN cp crates/compiler/builtins/bitcode/src/str.zig bench-folder/crates/compiler/builtins/bitcode/src
RUN cp target/release/roc bench-folder/target/release
# copy the most recent time bench to bench-folder

View file

@ -115,7 +115,7 @@ Create a new file called `Hello.roc` and put this inside it:
```coffee
app "hello"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout]
provides [main] to pf
@ -124,8 +124,8 @@ main = Stdout.line "I'm a Roc application!"
> **NOTE:** This assumes you've put Hello.roc in the root directory of the Roc
> source code. If you'd like to put it somewhere else, you'll need to replace
> `"examples/interactive/cli-platform/main.roc"` with the path to the
> `examples/interactive/cli-platform/main.roc` file in that source code. In the future,
> `"examples/cli/cli-platform/main.roc"` with the path to the
> `examples/cli/cli-platform/main.roc` file in that source code. In the future,
> Roc will have the tutorial built in, and this aside will no longer be
> necessary!
@ -1257,7 +1257,7 @@ Let's take a closer look at the part of `Hello.roc` above `main`:
```coffee
app "hello"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout]
provides main to pf
```
@ -1275,14 +1275,14 @@ without running it by running `roc build Hello.roc`.
The remaining lines all involve the *platform* this application is built on:
```coffee
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout]
provides main to pf
```
The `packages { pf: "examples/interactive/cli-platform/main.roc" }` part says two things:
The `packages { pf: "examples/cli/cli-platform/main.roc" }` part says two things:
- We're going to be using a *package* (that is, a collection of modules) called `"examples/interactive/cli-platform/main.roc"`
- We're going to be using a *package* (that is, a collection of modules) called `"examples/cli/cli-platform/main.roc"`
- We're going to name that package `pf` so we can refer to it more concisely in the future.
The `imports [pf.Stdout]` line says that we want to import the `Stdout` module
@ -1302,16 +1302,16 @@ calling a function named `line` which is exposed by a module named
When we write `imports [pf.Stdout]`, it specifies that the `Stdout`
module comes from the `pf` package.
Since `pf` was the name we chose for the `examples/interactive/cli-platform/main.roc`
package (when we wrote `packages { pf: "examples/interactive/cli-platform/main.roc" }`),
Since `pf` was the name we chose for the `examples/cli/cli-platform/main.roc`
package (when we wrote `packages { pf: "examples/cli/cli-platform/main.roc" }`),
this `imports` line tells the Roc compiler that when we call `Stdout.line`, it
should look for that `line` function in the `Stdout` module of the
`examples/interactive/cli-platform/main.roc` package.
`examples/cli/cli-platform/main.roc` package.
## Tasks
Tasks are technically not part of the Roc language, but they're very common in
platforms. Let's use the CLI platform in `examples/interactive/cli-platform/main.roc` as an example!
platforms. Let's use the CLI platform in `examples/cli/cli-platform/main.roc` as an example!
In the CLI platform, we have four operations we can do:
@ -1326,7 +1326,7 @@ First, let's do a basic "Hello World" using the tutorial app.
```coffee
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout]
provides [main] to pf
@ -1363,7 +1363,7 @@ Let's change `main` to read a line from `stdin`, and then print it back out agai
```swift
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Stdin, pf.Task]
provides [main] to pf
@ -1413,7 +1413,7 @@ This works, but we can make it a little nicer to read. Let's change it to the fo
```haskell
app "cli-tutorial"
packages { pf: "examples/interactive/cli-platform/main.roc" }
packages { pf: "examples/cli/cli-platform/main.roc" }
imports [pf.Stdout, pf.Stdin, pf.Task.{ await }]
provides [main] to pf

View file

@ -227,7 +227,7 @@ fn calc_hashes_for_folder(benches_path_str: &str) -> HashMap<String, String> {
}
fn check_if_bench_executables_changed() -> bool {
let bench_folder_str = "/examples/benchmarks/";
let bench_folder_str = "/crates/cli_testing_examples/benchmarks/";
let main_benches_path_str = [BENCH_FOLDER_MAIN, bench_folder_str].join("");
let main_bench_hashes = calc_hashes_for_folder(&main_benches_path_str);

View file

@ -707,7 +707,7 @@ mod cli_run {
all_benchmarks.insert(benchmark.filename, benchmark);
)*
check_for_benchmarks("../../examples/benchmarks", &mut all_benchmarks);
check_for_benchmarks("../../crates/cli_testing_examples/benchmarks", &mut all_benchmarks);
}
}
}

View file

@ -1,5 +1,5 @@
app "type-error"
packages { pf: "../../../../examples/interactive/cli-platform/main.roc" }
packages { pf: "../../../../examples/cli/cli-platform/main.roc" }
imports [pf.Stdout.{ line }, pf.Task.{ await }]
provides [main] to pf

View file

@ -0,0 +1,6 @@
*.dSYM
libhost.a
libapp.so
dynhost
preprocessedhost
metadata

View file

@ -3,12 +3,12 @@
To run this website, first compile either of these identical apps:
```bash
# Option A: Compile examples/platform-switching/rocLovesWebAssembly.roc
cargo run -- build --target=wasm32 examples/platform-switching/rocLovesWebAssembly.roc
# Option A: Compile crates/cli_testing_examples/platform-switching/rocLovesWebAssembly.roc
cargo run -- build --target=wasm32 crates/cli_testing_examples/platform-switching/rocLovesWebAssembly.roc
# Option B: Compile examples/platform-switching/main.roc with `pf: "web-assembly-platform/main.roc"` and move the result
cargo run -- build --target=wasm32 examples/platform-switching/main.roc
(cd examples/platform-switching && mv rocLovesPlatforms.wasm web-assembly-platform/rocLovesWebAssembly.wasm)
# Option B: Compile crates/cli_testing_examples/platform-switching/main.roc with `pf: "web-assembly-platform/main.roc"` and move the result
cargo run -- build --target=wasm32 crates/cli_testing_examples/platform-switching/main.roc
(cd crates/cli_testing_examples/platform-switching && mv rocLovesPlatforms.wasm web-assembly-platform/rocLovesWebAssembly.wasm)
```
Then `cd` into the website directory
@ -16,7 +16,7 @@ and run any web server that can handle WebAssembly.
For example, with `http-server`:
```bash
cd examples/platform-switching/web-assembly-platform
cd crates/cli_testing_examples/platform-switching/web-assembly-platform
npm install -g http-server
http-server
```

View file

@ -373,7 +373,7 @@ pub fn build_zig_host_wasm32(
"c",
"-target",
zig_target,
// "-femit-llvm-ir=/home/folkertdev/roc/roc/examples/benchmarks/platform/host.ll",
// "-femit-llvm-ir=/home/folkertdev/roc/roc/crates/cli_testing_examples/benchmarks/platform/host.ll",
"-fPIC",
"--strip",
];
@ -1176,7 +1176,7 @@ fn link_wasm32(
"-O",
"ReleaseSmall",
// useful for debugging
// "-femit-llvm-ir=/home/folkertdev/roc/roc/examples/benchmarks/platform/host.ll",
// "-femit-llvm-ir=/home/folkertdev/roc/roc/crates/cli_testing_examples/benchmarks/platform/host.ll",
])
.spawn()?;

View file

@ -14,7 +14,7 @@ Run examples as follows:
roc run hello-world/main.roc
```
`examples/benchmarks/` contains some larger examples.
`crates/cli_testing_examples/benchmarks/` contains some larger examples.
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
Some examples like `crates/cli_testing_examples/benchmarks/NQueens.roc` require input after running.
For NQueens, input 10 in the terminal and press enter.

View file

@ -6,7 +6,7 @@ play around with as long as you have a high tolerance for missing features and c
The [tutorial](../TUTORIAL.md) is the best place to learn about how to use the language - it assumes no prior knowledge of Roc or similar languages. (If you already know [Elm](https://elm-lang.org/), then [Roc for Elm Programmers](https://github.com/roc-lang/roc/blob/main/roc-for-elm-programmers.md) may be of interest.)
There's also a folder of [examples](https://github.com/roc-lang/roc/tree/main/examples) - the [CLI form example](https://github.com/roc-lang/roc/tree/main/examples/interactive/form.roc) in particular is a reasonable starting point to build on.
There's also a folder of [examples](https://github.com/roc-lang/roc/tree/main/examples) - the [CLI form example](https://github.com/roc-lang/roc/tree/main/examples/cli/form.roc) in particular is a reasonable starting point to build on.
If you have a specific question, the [FAQ](../FAQ.md) might have an answer, although [Roc Zulip chat](https://roc.zulipchat.com) is overall the best place to ask questions and get help! It's also where we discuss [ideas](https://roc.zulipchat.com/#narrow/stream/304641-ideas) for the language. If you want to get involved in contributing to the language, Zulip is also a great place to ask about good first projects.
@ -27,10 +27,10 @@ cd examples
roc run helloWorld.roc
```
Some examples like `examples/benchmarks/NQueens.roc` require input after running.
Some examples like `crates/cli_testing_examples/benchmarks/NQueens.roc` require input after running.
For NQueens, input 10 in the terminal and press enter.
[examples/benchmarks](examples/benchmarks) contains larger examples.
[crates/cli_testing_examples/benchmarks](crates/cli_testing_examples/benchmarks) contains larger examples.
**Tip:** when programming in roc, we recommend to execute `./roc check myproject/Foo.roc` before `./roc myproject/Foo.roc` or `./roc build myproject/Foo.roc`. `./roc check` can produce clear error messages in cases where building/running may panic.

View file

@ -44,9 +44,9 @@ you need to install one or more of these platform language compilers, too.
```sh
# Note: If you installed Rust in this terminal session, you'll need to open a new one first!
./roc examples/platform-switching/rocLovesRust.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesRust.roc
./roc examples/platform-switching/rocLovesZig.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesZig.roc
./roc examples/platform-switching/rocLovesC.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesC.roc
```

View file

@ -40,9 +40,9 @@ you need to install one or more of these platform language compilers, too.
```sh
# Note: If you installed rust in this terminal session, you'll need to open a new one first!
./roc examples/platform-switching/rocLovesRust.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesRust.roc
./roc examples/platform-switching/rocLovesZig.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesZig.roc
./roc examples/platform-switching/rocLovesC.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesC.roc
```

View file

@ -40,9 +40,9 @@ you need to install one or more of these platform language compilers, too.
```sh
# Note: If you installed rust in this terminal session, you'll need to open a new one first!
./roc examples/platform-switching/rocLovesRust.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesRust.roc
./roc examples/platform-switching/rocLovesZig.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesZig.roc
./roc examples/platform-switching/rocLovesC.roc
./roc crates/cli_testing_examples/platform-switching/rocLovesC.roc
```

View file

@ -7,11 +7,11 @@
1. Run examples:
```sh
cargo run examples/platform-switching/rocLovesRust.roc
cargo run crates/cli_testing_examples/platform-switching/rocLovesRust.roc
# This requires installing the Zig compiler, too.
cargo run examples/platform-switching/rocLovesZig.roc
cargo run crates/cli_testing_examples/platform-switching/rocLovesZig.roc
# This requires installing the `clang` C compiler, too.
cargo run examples/platform-switching/rocLovesC.roc
cargo run crates/cli_testing_examples/platform-switching/rocLovesC.roc
```

View file

@ -45,7 +45,7 @@ export ROC_DOCS_URL_ROOT=/examples/cli
# Until https://github.com/roc-lang/roc/issues/3280 is done,
# manually exclude the Internal* modules and `main.roc`.
ls examples/interactive/cli-platform/*.roc | grep -v Internal | grep -v main.roc | grep -v Effect.roc | xargs cargo run --bin roc-docs
ls examples/cli/cli-platform/*.roc | grep -v Internal | grep -v main.roc | grep -v Effect.roc | xargs cargo run --bin roc-docs
mkdir www/build/examples
rm generated-docs/*.* # we already copied over the *.js and *.css files earlier, so just drop these.