Merge pull request #23 from return/crystal-to-rust

Add Crystal to Rust example.
This commit is contained in:
Alex Crichton
2019-01-07 09:44:41 -06:00
committed by GitHub
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
}