Skip to content

Commit f8f4dc1

Browse files
add examples copied from Roc
1 parent 0630231 commit f8f4dc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+8447
-0
lines changed

platforms/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Platforms
2+
3+
This folder includes examples for roc platforms and interop with other languages.
4+
5+
*Templates & Embedding/Interop Examples* 🗺
6+
7+
You can also find some platform tempalates that are developed by the community. Here are some examples;
8+
- [Zig platform template](https://github.com/lukewilliamboswell/roc-platform-template-zig)
9+
- [Rust platform template](https://github.com/lukewilliamboswell/roc-platform-template-rust)
10+
- [Go platform template](https://github.com/lukewilliamboswell/roc-platform-template-go)
11+
- [Swift platform template](https://github.com/lukewilliamboswell/roc-platform-template-swift)
12+
- [C platform template](https://github.com/lukewilliamboswell/roc-platform-template-c)
13+
- [Python interop](https://github.com/roc-lang/roc/tree/main/examples/python-interop)
14+
- [Ruby interop](https://github.com/roc-lang/roc/tree/main/examples/ruby-interop)
15+
- [NodeJs interop](https://github.com/roc-lang/roc/tree/main/examples/nodejs-interop)
16+
- [Java interop](https://github.com/roc-lang/roc/tree/main/examples/jvm-interop)

platforms/glue/glue.roc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
app [main] { pf: platform "rust-platform/main.roc" }
2+
3+
main =
4+
msg = "Roc <3 Rust, also on stderr!\n"
5+
StdoutWrite "Roc <3 Rust!\n" \{} ->
6+
StderrWrite msg \{} ->
7+
Done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.x86_64-pc-windows-gnu]
2+
linker = "zig-cc"
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "host"
3+
version = "0.0.1"
4+
authors = ["The Roc Contributors"]
5+
license = "UPL-1.0"
6+
edition = "2021"
7+
links = "app"
8+
9+
[lib]
10+
name = "host"
11+
path = "src/lib.rs"
12+
crate-type = ["staticlib", "lib"]
13+
14+
[[bin]]
15+
name = "host"
16+
path = "src/main.rs"
17+
18+
[dependencies]
19+
roc_app = { path = "roc_app" }
20+
roc_std = { path = "roc_std" }
21+
libc = "0.2"
22+
23+
[workspace]

platforms/glue/rust-platform/build.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
#[cfg(not(windows))]
3+
println!("cargo:rustc-link-lib=dylib=app");
4+
5+
#[cfg(windows)]
6+
println!("cargo:rustc-link-lib=dylib=libapp");
7+
8+
println!("cargo:rustc-link-search=.");
9+
}

platforms/glue/rust-platform/host.c

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern int rust_main();
2+
3+
int main() { return rust_main(); }

platforms/glue/rust-platform/main.roc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
platform "echo-in-rust"
2+
requires {} { main : _ }
3+
exposes []
4+
packages {}
5+
imports []
6+
provides [mainForHost]
7+
8+
# mainForHost : [StdoutWrite Str (({} -> Op) as Fx0), StderrWrite Str (({} -> Op) as Fx1), Done] as Op
9+
mainForHost : [StdoutWrite Str ({} -> Op), StderrWrite Str ({} -> Op), Done] as Op
10+
mainForHost = main
11+
12+
# mainForHost : { x: Str, y: {} -> Str }
13+
# mainForHost =
14+
# y = "foo"
15+
#
16+
# when main is
17+
# _ -> { x: "bar", y: \{} -> y }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[toolchain]
2+
channel = "1.77.2"
3+
4+
profile = "default"
5+
6+
components = [
7+
# for usages of rust-analyzer or similar tools inside `nix develop`
8+
"rust-src"
9+
]

0 commit comments

Comments
 (0)