From abca643dd4175aba98b617d16c4af4d5d7e898cb Mon Sep 17 00:00:00 2001 From: Wesley Hill Date: Mon, 18 Nov 2019 14:40:16 +0000 Subject: [PATCH] Add c# to rust example --- csharp-to-rust/.gitignore | 3 +++ csharp-to-rust/Cargo.toml | 8 ++++++++ csharp-to-rust/Makefile | 9 +++++++++ csharp-to-rust/src/double.cs | 15 +++++++++++++++ csharp-to-rust/src/lib.rs | 4 ++++ 5 files changed, 39 insertions(+) create mode 100644 csharp-to-rust/.gitignore create mode 100644 csharp-to-rust/Cargo.toml create mode 100644 csharp-to-rust/Makefile create mode 100644 csharp-to-rust/src/double.cs create mode 100644 csharp-to-rust/src/lib.rs diff --git a/csharp-to-rust/.gitignore b/csharp-to-rust/.gitignore new file mode 100644 index 0000000..6936990 --- /dev/null +++ b/csharp-to-rust/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +Cargo.lock diff --git a/csharp-to-rust/Cargo.toml b/csharp-to-rust/Cargo.toml new file mode 100644 index 0000000..bea8dbb --- /dev/null +++ b/csharp-to-rust/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "csharp-to-rust" +version = "0.1.0" +authors = ["Wesley Hill "] + +[lib] +name = "double_input" +crate-type = ["cdylib"] diff --git a/csharp-to-rust/Makefile b/csharp-to-rust/Makefile new file mode 100644 index 0000000..ac1d60c --- /dev/null +++ b/csharp-to-rust/Makefile @@ -0,0 +1,9 @@ +all: target/debug/libdouble_input + csc src/double.cs + mono ./double.exe + +target/debug/libdouble_input: src/lib.rs Cargo.toml + rustc --crate-name double_input src/lib.rs --crate-type cdylib -o libdouble_input + +clean: + rm -rf target double.exe diff --git a/csharp-to-rust/src/double.cs b/csharp-to-rust/src/double.cs new file mode 100644 index 0000000..174f7c5 --- /dev/null +++ b/csharp-to-rust/src/double.cs @@ -0,0 +1,15 @@ +using System; +using System.Runtime.InteropServices; + +namespace DoubleClass { + + class Double { + [DllImport ("libdouble_input")] + public static extern int double_input (int input); + + + public static void Main (string[] args) { + Console.WriteLine (double_input (2)); + } + } +} diff --git a/csharp-to-rust/src/lib.rs b/csharp-to-rust/src/lib.rs new file mode 100644 index 0000000..03c626e --- /dev/null +++ b/csharp-to-rust/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern fn double_input(input: i32) -> i32 { + input * 2 +} \ No newline at end of file