Add Crystal to Rust example.

This commit is contained in:
Calvin Hill
2019-01-07 09:19:38 +00:00
parent 0ab5fe120e
commit e373c1994c
4 changed files with 34 additions and 0 deletions

View 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
View 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

View File

@@ -0,0 +1,6 @@
@[Link("double_input")]
lib RustLib
fun double_input(input: Int32) : Int32
end
puts RustLib.double_input(2)

View File

@@ -0,0 +1,4 @@
#[no_mangle]
pub extern "C" fn double_input(input: i32) -> i32 {
input * 2
}