Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example platforms moved from Roc #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions platforms/README.md
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this comment here so I don't forget, tests still need to be added to ci_scripts/all_tests.sh

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Platforms

This folder includes examples for roc platforms and interop with other languages.

*Templates & Embedding/Interop Examples* 🗺

You can also find some platform tempalates that are developed by the community. Here are some examples;
- [Zig platform template](https://github.com/lukewilliamboswell/roc-platform-template-zig)
- [Rust platform template](https://github.com/lukewilliamboswell/roc-platform-template-rust)
- [Go platform template](https://github.com/lukewilliamboswell/roc-platform-template-go)
- [Swift platform template](https://github.com/lukewilliamboswell/roc-platform-template-swift)
- [C platform template](https://github.com/lukewilliamboswell/roc-platform-template-c)
- [Python interop](https://github.com/roc-lang/roc/tree/main/examples/python-interop)
- [Ruby interop](https://github.com/roc-lang/roc/tree/main/examples/ruby-interop)
- [NodeJs interop](https://github.com/roc-lang/roc/tree/main/examples/nodejs-interop)
- [Java interop](https://github.com/roc-lang/roc/tree/main/examples/jvm-interop)
7 changes: 7 additions & 0 deletions platforms/glue/glue.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
app [main] { pf: platform "rust-platform/main.roc" }

main =
msg = "Roc <3 Rust, also on stderr!\n"
StdoutWrite "Roc <3 Rust!\n" \{} ->
StderrWrite msg \{} ->
Done
2 changes: 2 additions & 0 deletions platforms/glue/rust-platform/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.x86_64-pc-windows-gnu]
linker = "zig-cc"
23 changes: 23 additions & 0 deletions platforms/glue/rust-platform/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "host"
version = "0.0.1"
authors = ["The Roc Contributors"]
license = "UPL-1.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The license should be changed to the license of this repo "CC0 1.0"

edition = "2021"
links = "app"

[lib]
name = "host"
path = "src/lib.rs"
crate-type = ["staticlib", "lib"]

[[bin]]
name = "host"
path = "src/main.rs"

[dependencies]
roc_app = { path = "roc_app" }
roc_std = { path = "roc_std" }
libc = "0.2"

[workspace]
9 changes: 9 additions & 0 deletions platforms/glue/rust-platform/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn main() {
#[cfg(not(windows))]
println!("cargo:rustc-link-lib=dylib=app");

#[cfg(windows)]
println!("cargo:rustc-link-lib=dylib=libapp");

println!("cargo:rustc-link-search=.");
}
3 changes: 3 additions & 0 deletions platforms/glue/rust-platform/host.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern int rust_main();

int main() { return rust_main(); }
17 changes: 17 additions & 0 deletions platforms/glue/rust-platform/main.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
platform "echo-in-rust"
requires {} { main : _ }
exposes []
packages {}
imports []
provides [mainForHost]

# mainForHost : [StdoutWrite Str (({} -> Op) as Fx0), StderrWrite Str (({} -> Op) as Fx1), Done] as Op
mainForHost : [StdoutWrite Str ({} -> Op), StderrWrite Str ({} -> Op), Done] as Op
mainForHost = main

# mainForHost : { x: Str, y: {} -> Str }
# mainForHost =
# y = "foo"
#
# when main is
# _ -> { x: "bar", y: \{} -> y }
9 changes: 9 additions & 0 deletions platforms/glue/rust-platform/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[toolchain]
channel = "1.77.2"

profile = "default"

components = [
# for usages of rust-analyzer or similar tools inside `nix develop`
"rust-src"
]
Loading
Loading