Add Crystal to Rust example.
This commit is contained in:
8
crystal-to-rust/Cargo.toml
Normal file
8
crystal-to-rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "crystal-to-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["Calvin Hill <calvin@hakobaito.co.uk>"]
|
||||
|
||||
[lib]
|
||||
name = "double_input"
|
||||
crate-type = ["dylib"]
|
||||
16
crystal-to-rust/Makefile
Normal file
16
crystal-to-rust/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
ifeq ($(shell uname),Darwin)
|
||||
EXT := dylib
|
||||
else
|
||||
EXT := so
|
||||
endif
|
||||
|
||||
all: target/debug/libdouble_input.$(EXT)
|
||||
LIBRARY_PATH=$(PWD)/target/debug:$(LIBRARY_PATH) crystal build src/double.cr -o double
|
||||
LD_LIBRARY_PATH=./target/debug ./double
|
||||
|
||||
target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
|
||||
cargo build
|
||||
cd src
|
||||
|
||||
clean:
|
||||
rm -rf target double double.dwarf
|
||||
6
crystal-to-rust/src/double.cr
Normal file
6
crystal-to-rust/src/double.cr
Normal file
@@ -0,0 +1,6 @@
|
||||
@[Link("double_input")]
|
||||
lib RustLib
|
||||
fun double_input(input: Int32) : Int32
|
||||
end
|
||||
|
||||
puts RustLib.double_input(2)
|
||||
4
crystal-to-rust/src/lib.rs
Normal file
4
crystal-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern "C" fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
Reference in New Issue
Block a user