NordSecurity / uniffi-bindgen-cs

C# bindings generator for uniffi-rs
https://github.com/NordSecurity/uniffi-bindgen-cs
Mozilla Public License 2.0
109 stars 21 forks source link

`bytes` typedef does not compile #78

Open arg0d opened 5 months ago

arg0d commented 5 months ago

UDL

[Custom]
typedef bytes SomeType

Generated C#

using SomeType = bytes[];

Error

C:\workspace\uniffi-bindgen-cs\dotnet-tests\UniffiCS\gen\custom_types_builtin.cs(19,15): error CS8936: Feature 'using type alias' is not available in C# 10.0. Please use language version 12.0 or greater. [C:\workspace\uniffi-bindgen-cs\dotnet-tests\UniffiCS\UniffiCS.csproj::TargetFramework=net48]

Test diff repro:

diff --git a/fixtures/custom-types-builtin/src/custom_types_builtin.udl b/fixtures/custom-types-builtin/src/custom_types_builtin.udl
index c71fb4f..24170e0 100644
--- a/fixtures/custom-types-builtin/src/custom_types_builtin.udl
+++ b/fixtures/custom-types-builtin/src/custom_types_builtin.udl
@@ -12,6 +12,9 @@ typedef string MyString;
 [Custom]
 typedef sequence<string> Array;

+[Custom]
+typedef bytes Bytes;
+
 [Custom]
 typedef record<string, string> Table;

@@ -51,6 +54,7 @@ typedef double Double;
 dictionary CustomTypesBuiltin {
     MyString string;
     Array array;
+    Bytes bytes;
     Table table;
     Boolean boolean;
     Int8 int8;
diff --git a/fixtures/custom-types-builtin/src/lib.rs b/fixtures/custom-types-builtin/src/lib.rs
index 9352f02..56de1ba 100644
--- a/fixtures/custom-types-builtin/src/lib.rs
+++ b/fixtures/custom-types-builtin/src/lib.rs
@@ -23,6 +23,7 @@ macro_rules! define_custom_builtin_type {

 define_custom_builtin_type!(MyString, String);
 define_custom_builtin_type!(Array, Vec<String>);
+define_custom_builtin_type!(Bytes, Vec<u8>);
 define_custom_builtin_type!(Table, HashMap<String, String>);
 define_custom_builtin_type!(Boolean, bool);
 define_custom_builtin_type!(Int8, i8);
@@ -39,6 +40,7 @@ define_custom_builtin_type!(Double, f64);
 pub struct CustomTypesBuiltin {
     string: MyString,
     array: Array,
+    bytes: Bytes,
     table: Table,
     boolean: Boolean,
     int8: Int8,
@@ -57,6 +59,7 @@ pub fn get_custom_types_builtin() -> CustomTypesBuiltin {
     return CustomTypesBuiltin {
         string: MyString("Hello, world!".to_string()),
         array: Array(vec!["Hello, world!".to_string()]),
+        bytes: Bytes(vec![0x13, 0x37]),
         table: Table(HashMap::from([("hello".to_string(), "world".to_string())])),
         boolean: Boolean(true),
         int8: Int8(i8::MAX),
arg0d commented 5 months ago

This would be solved by https://github.com/NordSecurity/uniffi-bindgen-cs/issues/54