Skip to content

Experimental .Net support #371

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
02db514
Docstrings for methods
AdamRzepka Jun 13, 2019
255e933
Merge branch 'python' into python-doc
AdamRzepka Jun 19, 2019
001b0e5
Merge branch 'python' into python-doc
AdamRzepka Jul 11, 2019
03bd3d9
merge
AdamRzepka Jul 23, 2019
c418075
Better error message passed to python exception
AdamRzepka Jul 23, 2019
9f662ae
Merge branch 'python' into python-doc
AdamRzepka Aug 6, 2019
f7ab35f
Merge branch 'python' into python-doc
AdamRzepka Aug 20, 2019
69eb690
python: catching panics at ffi border
AdamRzepka Oct 9, 2019
23edb6a
Merge branch 'master' into python
AdamRzepka Jan 18, 2020
32d3818
C++: automatically clone arguments passed by value
AdamRzepka Jan 18, 2020
84cf4ce
C++: Arc<T> support
AdamRzepka Jan 18, 2020
7ca18d6
C++: Vec of references and Vec of tuples
AdamRzepka Jan 18, 2020
eb21a6e
C++: optional enum class generation
AdamRzepka Jan 21, 2020
1c1dade
Merge branch 'master' into simteract
May 5, 2020
be516bd
Initial C# structure
May 20, 2020
38593db
[C#] Input arguments working
May 21, 2020
71d4e40
[C#] output primitive parameters working
May 21, 2020
95a638d
[C#] Refactor
May 22, 2020
902d504
[C#] Rust side code generation for classes
May 27, 2020
c61de55
[C#] Quick and dirty .NET high-level class wrapper
Jun 1, 2020
cdfa693
[C#] Passing classes as any argument
Jun 3, 2020
83f330a
[C#] String support
Jun 4, 2020
2c72c5b
[C#] Vectors kinda work
Jun 8, 2020
1c2227e
[C#] Option<T> handling
Jun 10, 2020
aaa514a
[C#] Safe handling of refs and values.
Jun 12, 2020
082098d
[C#] Option improvements
Jun 15, 2020
68b71d1
[C#] New Vec almost working
Jun 16, 2020
4621788
[C#] Vec should fully work
Jun 16, 2020
6225272
[C#] Slice and &str support
Jun 16, 2020
3c33e54
[C#] Results to exceptions conversion
Jun 16, 2020
37db0c0
[C#] Smart pointers implementation
Jun 18, 2020
602dad1
[C#] Smart Pointers tested and working
Jun 19, 2020
88e116c
[C#] Tuple2
AdamRzepka Jun 20, 2020
6e3e102
[C#] enum support
Jun 22, 2020
7c68fe2
Merge branch 'dotnet' of github.com:Simteract/rust_swig into dotnet
Jun 22, 2020
a8e6219
[C#] support for circular class dependencies
Jun 22, 2020
1e7f1c6
[C#] Fixed bug with tuples
Jun 22, 2020
7dd228d
[C#] Convert method names to CamelCase
Jun 22, 2020
06cf888
[C#] Docstrings
Jun 22, 2020
fcd6aea
[C#] Cleaning up
Jun 22, 2020
2a57517
[C#] Fixed mem leak in string handling
Jun 22, 2020
bb477e7
[C#] Get rid of "finalizer_code"
Jun 22, 2020
5210119
Merge branch 'simteract' into simteract-dotnet
Jun 22, 2020
fc62fa7
[C#] bugfix for Result mapping
Jun 23, 2020
cdda374
[C#] a few fixes
AdamRzepka Jun 25, 2020
40b20b6
[C#] Fixed handling of Result<()>
AdamRzepka Jun 26, 2020
dd7a442
[C#] On more fix for Result<()>
AdamRzepka Jun 27, 2020
84c5c2f
[C#] Specyfing generation path in config
AdamRzepka Jul 9, 2020
e8f0248
get rid of CS0114 warnings
Aug 25, 2020
b2d8a1f
Add comment - CS0114 warning
Aug 26, 2020
1086289
[C#] cleaning up dotnet_test
Jan 3, 2021
0786e63
merge upstream/master into simteract-dotnet
AdamRzepka Jan 7, 2021
31a2381
[C++] Arc support
AdamRzepka Jan 7, 2021
304f722
Merge remote-tracking branch 'upstream/master' into simteract-dotnet
AdamRzepka Jan 7, 2021
1ebabea
Post-merge fixes
AdamRzepka Jan 7, 2021
308b015
Revert Simteract-specific changes
AdamRzepka Jan 7, 2021
7becd75
Rever simteract-specific changes 2
AdamRzepka Jan 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ jni_tests/java/com/example/rust
/cpp_tests/c++/build_with_boost
target/
/macroslib/target/
/dotnet_tests/flapigen_test_dotnet
/dotnet_tests/dotnet/bin/
/dotnet_tests/dotnet/obj/
/dotnet_tests/dotnet/*.dll
.vscode
Cargo.lock
Cargo.lock
/Cargo.toml
android-example/app/src/main/java/net/akaame/myapplication/JNIReachabilityFence.java
38 changes: 37 additions & 1 deletion ci_build_and_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

JNI_TESTS = "jni_tests"
PYTHON_TESTS = "python_tests"
DOTNET_TESTS = "dotnet_tests"
CPP_TESTS = "cpp_tests"
ANDROID_TESTS = "android-example"
UNIT_TESTS = "unit_tests"
Expand Down Expand Up @@ -223,6 +224,34 @@ def test_python(is_windows: bool, test_cfg: Set[str]):
shutil.copyfile(os.path.join(target_dir, lib_name), "python_tests/python/flapigen_test_python.so")
subprocess.check_call(["python3", "main.py"], cwd = "python_tests/python")

@show_timing
def test_dotnet(test_cfg):
for cfg in test_cfg:
cmd = ["cargo", "build", "-v", "--package", "flapigen_test_dotnet_native"]
if cfg == RELEASE:
cmd.append("--release")
env = os.environ.copy()
subprocess.check_call(cmd, shell = False, env = env)

target_dir = find_path_to_cargo_artifacts("dotnet_tests", cfg)
native_lib_name = "libflapigen_test_dotnet_native.so"
if sys.platform == "darwin":
native_lib_name = "libflapigen_test_dotnet_native.dylib"
elif sys.platform.startswith("win"):
native_lib_name = "flapigen_test_dotnet_native.dll"

test_projekt_target_dir = "dotnet_tests/dotnet/bin/Debug/netcoreapp3.1"

os.makedirs(test_projekt_target_dir, exist_ok=True)
shutil.copyfile(os.path.join(target_dir, native_lib_name), os.path.join(test_projekt_target_dir, native_lib_name))

# Build managed wrapper dll.
subprocess.check_call(["dotnet", "build"], cwd = "dotnet_tests/flapigen_test_dotnet")
shutil.copyfile("dotnet_tests/flapigen_test_dotnet/bin/Debug/netstandard2.0/flapigen_test_dotnet.dll", "dotnet_tests/dotnet/flapigen_test_dotnet.dll")

# Run test
subprocess.check_call(["dotnet", "test", '--logger:"console;verbosity=detailed"'], cwd = "dotnet_tests/dotnet")


@show_timing
def build_cargo_docs():
Expand Down Expand Up @@ -265,7 +294,7 @@ def main():
sys.stdout.flush()

test_cfg = set([RELEASE, DEBUG])
test_set = set([JNI_TESTS, CPP_TESTS, ANDROID_TESTS, UNIT_TESTS, DOC_TESTS, PYTHON_TESTS])
test_set = set([JNI_TESTS, CPP_TESTS, ANDROID_TESTS, UNIT_TESTS, DOC_TESTS, PYTHON_TESTS, DOTNET_TESTS])
for arg in sys.argv[1:]:
if arg == "--skip-android-tests":
test_set.remove(ANDROID_TESTS)
Expand All @@ -277,12 +306,16 @@ def main():
test_set.remove(JNI_TESTS)
elif arg == "--skip-python-tests":
test_set.remove(PYTHON_TESTS)
elif arg == "--skip-dotnet-tests":
test_set.remove(DOTNET_TESTS)
elif arg == "--android-only-tests":
test_set = set([ANDROID_TESTS])
elif arg == "--rust-unit-tests-only":
test_set = set([UNIT_TESTS])
elif arg == "--python-only-tests":
test_set = set([PYTHON_TESTS])
elif arg == "--dotnet-only-tests":
test_set = set([DOTNET_TESTS])
else:
raise Exception("Fatal Error: unknown option: %s" % arg)

Expand Down Expand Up @@ -324,5 +357,8 @@ def main():
if PYTHON_TESTS in test_set:
test_python(is_windows, test_cfg)

if DOTNET_TESTS in test_set:
test_dotnet(test_cfg)

if __name__ == "__main__":
main()
15 changes: 15 additions & 0 deletions dotnet_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "flapigen_test_dotnet_native"
version = "0.1.0"
authors = ["Adam Rzepka <adam@simteract.com>"]
build = "build.rs"
edition = "2018"

[lib]
name = "flapigen_test_dotnet_native"
crate-type = ["cdylib"]

[build-dependencies]
flapigen = { path = "../macroslib" }
env_logger = "0.7"
log = "0.4"
29 changes: 29 additions & 0 deletions dotnet_tests/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::{env, path::Path, time::Instant};

use flapigen::{DotNetConfig, LanguageConfig};

fn main() {
env_logger::init();

let now = Instant::now();

let out_dir = env::var("OUT_DIR").unwrap();
flapigen_expand(
Path::new("src/glue.rs.in"),
&Path::new(&out_dir).join("glue.rs"),
);
let expand_time = now.elapsed();
println!(
"flapigen expand time: {}",
expand_time.as_secs() as f64 + (expand_time.subsec_nanos() as f64) / 1_000_000_000.
);
println!("cargo:rerun-if-changed=src/glue.rs.in");
println!("cargo:rerun-if-changed=src/lib.rs");
}

fn flapigen_expand(from: &Path, out: &Path) {
println!("Run flapigen_expand");
let config = DotNetConfig::new("flapigen_test_dotnet".to_owned(), "flapigen_test_dotnet".into());
let swig_gen = flapigen::Generator::new(LanguageConfig::DotNetConfig(config));
swig_gen.expand("flapigen_test_dotnet_native", from, out);
}
63 changes: 63 additions & 0 deletions dotnet_tests/dotnet/Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using Xunit;
using flapigen_test_dotnet;

namespace dotnet
{
public class UnitTest
{
[Fact]
/// "Smoke" tests for flapigen dotnet backend.
/// Note, that some function does not return anything. They are called here just to verify, that there are no crashes.
public void TestAll()
{
TestStaticClass.Hello();
TestStaticClass.PrintNumber(123);
Assert.Equal(3, TestStaticClass.Add(1, 2));
Assert.Equal("Concatenated String", TestStaticClass.Concat("Concatenated ", "String"));
Assert.Equal("Concatenated str", TestStaticClass.Concat("Concatenated ", "str"));

var obj = new TestClass();
Assert.Equal(0, obj.Get());
obj.Increment();
Assert.Equal(1, obj.Get());
obj.Add(3);
obj.Print();
Assert.Equal(4, obj.Get());

TestStaticClass.TestObjByValue(obj);

var vec = new List<int>();
vec.Add(1);
vec.Add(2);

TestStaticClass.PrintVecLen(vec);
var new_vec = TestStaticClass.GetVec();
Assert.Equal(3, new_vec.Count);
Assert.Equal(5, new_vec[0]);
Assert.Equal(6, new_vec[1]);
Assert.Equal(7, new_vec[2]);

Assert.Equal(0, TestStaticClass.MaybeReturnClass(new Option<string>("asdf")).Value.Get());
Assert.False(TestStaticClass.MaybeAddOne(new Option<int>()).IsSome);

// This shouldn't throw.
TestStaticClass.TryCreateObjectOk();
// But this one should.
Assert.Throws<flapigen_test_dotnet.Error>(() => TestStaticClass.TryCreateObjectErr());

var arc_mutex = new TestArcMutex();
arc_mutex.Inc();
Assert.Equal("1", arc_mutex.ToString());
Assert.Equal("1", TestArcMutex.ToStringArc(arc_mutex));

Assert.Equal(TestEnum.A, TestStaticClass.ReverseEnum(TestEnum.B));

var tuple = TestStaticClass.GetTuple();
Assert.Equal(0, tuple.Item1);
Assert.Equal("0", tuple.Item2);
}
}
}

17 changes: 17 additions & 0 deletions dotnet_tests/dotnet/dotnet.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
<Reference Include="flapigen_test_dotnet" />
</ItemGroup>

</Project>
Loading