Adding Julia and C++ examples
This commit is contained in:
8
julia-to-rust/Cargo.toml
Normal file
8
julia-to-rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "julia-to-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["timmonfette1 <monfette.timothy@gmail.com>"]
|
||||
|
||||
[lib]
|
||||
name = "double_input"
|
||||
crate-type = ["dylib"]
|
||||
14
julia-to-rust/Makefile
Normal file
14
julia-to-rust/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
ifeq ($(shell uname),Darwin)
|
||||
EXT := dylib
|
||||
else
|
||||
EXT := so
|
||||
endif
|
||||
|
||||
all: target/debug/libdouble_input.$(EXT)
|
||||
julia src/main.jl
|
||||
|
||||
target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
|
||||
cargo build
|
||||
|
||||
clean:
|
||||
rm -rf target
|
||||
4
julia-to-rust/src/lib.rs
Normal file
4
julia-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
7
julia-to-rust/src/main.jl
Normal file
7
julia-to-rust/src/main.jl
Normal file
@@ -0,0 +1,7 @@
|
||||
input = Int32(10)
|
||||
output = ccall((:double_input, "target/debug/libdouble_input"),
|
||||
Int32, (Int32,), input)
|
||||
|
||||
print(input)
|
||||
print(" * 2 = ")
|
||||
println(output)
|
||||
Reference in New Issue
Block a user