Add Swift to Rust example.
This commit is contained in:
8
swift-to-rust/Cargo.toml
Normal file
8
swift-to-rust/Cargo.toml
Normal 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
15
swift-to-rust/Makefile
Normal 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
|
||||
1
swift-to-rust/src/double.h
Normal file
1
swift-to-rust/src/double.h
Normal file
@@ -0,0 +1 @@
|
||||
int double_input(int input);
|
||||
4
swift-to-rust/src/lib.rs
Normal file
4
swift-to-rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#[no_mangle]
|
||||
pub extern fn double_input(input: i32) -> i32 {
|
||||
input * 2
|
||||
}
|
||||
1
swift-to-rust/src/main.swift
Normal file
1
swift-to-rust/src/main.swift
Normal file
@@ -0,0 +1 @@
|
||||
print(double_input(2))
|
||||
Reference in New Issue
Block a user