Add Swift to Rust example.

This commit is contained in:
Calvin Hill
2019-01-07 09:11:54 +00:00
parent 0ab5fe120e
commit e51997184e
5 changed files with 29 additions and 0 deletions

8
swift-to-rust/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
name = "swift-to-rust"
version = "0.1.0"
authors = ["Calvin Hill <calvin@hakobaito.co.uk>"]
[lib]
name = "double_input"
crate-type = ["dylib"]

15
swift-to-rust/Makefile Normal file
View File

@@ -0,0 +1,15 @@
ifeq ($(shell uname),Darwin)
EXT := dylib
else
EXT := so
endif
all: target/debug/libdouble_input.$(EXT)
swiftc src/main.swift -import-objc-header src/double.h -L./target/debug -ldouble_input -o double
LD_LIBRARY_PATH=./target/debug ./double
target/debug/libdouble_input.$(EXT): src/lib.rs Cargo.toml
cargo build
clean:
rm -rf target double

View File

@@ -0,0 +1 @@
int double_input(int input);

4
swift-to-rust/src/lib.rs Normal file
View File

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

View File

@@ -0,0 +1 @@
print(double_input(2))