diff --git a/net/rs/Cargo.lock b/net/rs/Cargo.lock index f057dfeb..b3df8240 100644 --- a/net/rs/Cargo.lock +++ b/net/rs/Cargo.lock @@ -116,16 +116,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "csbindgen" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c26b9831049b947d154bba920e4124053def72447be6fb106a96f483874b482a" -dependencies = [ - "regex", - "syn 2.0.87", -] - [[package]] name = "dirs-next" version = "2.0.0" @@ -588,7 +578,6 @@ version = "0.6.3" dependencies = [ "anyhow", "convert_case", - "csbindgen", "genco", "insta", "itertools 0.13.0", diff --git a/net/rs/Cargo.toml b/net/rs/Cargo.toml index 8dc05dd7..e72e56f4 100644 --- a/net/rs/Cargo.toml +++ b/net/rs/Cargo.toml @@ -15,7 +15,6 @@ sails-idl-parser = "=0.6.3" # others anyhow = "1" convert-case = { package = "convert_case", version = "0.6" } -csbindgen = "1.9" genco = "0.17" insta = "1.41" itertools = "0.13" diff --git a/net/rs/client-gen/Cargo.toml b/net/rs/client-gen/Cargo.toml index ef190654..761cc340 100644 --- a/net/rs/client-gen/Cargo.toml +++ b/net/rs/client-gen/Cargo.toml @@ -11,9 +11,6 @@ repository.workspace = true [lib] crate-type = ["cdylib", "rlib"] -[build-dependencies] -csbindgen.workspace = true - [dependencies] anyhow.workspace = true convert-case.workspace = true diff --git a/net/rs/client-gen/build.rs b/net/rs/client-gen/build.rs deleted file mode 100644 index 589ff5c5..00000000 --- a/net/rs/client-gen/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - csbindgen::Builder::default() - .input_extern_file("src/lib.rs") - .csharp_dll_name("sails_net_client_gen") - .csharp_namespace("Sails.ClientGenerator") - .generate_csharp_file("../../src/Sails.ClientGenerator/NativeMethods.g.cs") - .unwrap(); -} diff --git a/net/src/Sails.ClientGenerator/NativeMethods.Loader.cs b/net/src/Sails.ClientGenerator/NativeMethods.Loader.cs index 663ee6fd..e5e1f9a6 100644 --- a/net/src/Sails.ClientGenerator/NativeMethods.Loader.cs +++ b/net/src/Sails.ClientGenerator/NativeMethods.Loader.cs @@ -11,15 +11,15 @@ internal static unsafe partial class NativeMethods internal static IntPtr LoadNativeLibrary() { // Determine where to extract the DLL - var tempDirectory = Path.Combine(Path.GetTempPath(), __DllName); + var tempDirectory = Path.Combine(Path.GetTempPath(), DllName); Directory.CreateDirectory(tempDirectory); var (platform, extension) = GetResourcePlatform(); - var nativeLibraryPath = Path.Combine(tempDirectory, __DllName + extension); + var nativeLibraryPath = Path.Combine(tempDirectory, DllName + extension); // Extract the DLL only if it doesn't already exist if (!File.Exists(nativeLibraryPath)) { - ExtractResourceToFile($"{platform}.{__DllName}{extension}", nativeLibraryPath); + ExtractResourceToFile($"{platform}.{DllName}{extension}", nativeLibraryPath); } var ret = LibraryLoader.GetPlatformDefaultLoader().LoadNativeLibraryByPath(nativeLibraryPath); if (ret == IntPtr.Zero) diff --git a/net/src/Sails.ClientGenerator/NativeMethods.cs b/net/src/Sails.ClientGenerator/NativeMethods.cs new file mode 100644 index 00000000..565f5971 --- /dev/null +++ b/net/src/Sails.ClientGenerator/NativeMethods.cs @@ -0,0 +1,24 @@ +using System.Runtime.InteropServices; + +namespace Sails.ClientGenerator; + +internal static unsafe partial class NativeMethods +{ + private const string DllName = "sails_net_client_gen"; + + /// + /// # Safety + /// + /// Function [`free_c_string`] should be called after this function + /// + [DllImport(DllName, EntryPoint = "generate_dotnet_client", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern byte* generate_dotnet_client(byte* program_utf8, int program_len, byte* config_utf8, int config_len); + + /// + /// # Safety + /// + /// This function should not be called before the [`generate_dotnet_client`] + /// + [DllImport(DllName, EntryPoint = "free_c_string", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + internal static extern void free_c_string(byte* str); +} diff --git a/net/src/Sails.ClientGenerator/NativeMethods.g.cs b/net/src/Sails.ClientGenerator/NativeMethods.g.cs deleted file mode 100644 index 5cbf23b7..00000000 --- a/net/src/Sails.ClientGenerator/NativeMethods.g.cs +++ /dev/null @@ -1,40 +0,0 @@ -// -// This code is generated by csbindgen. -// DON'T CHANGE THIS DIRECTLY. -// -#pragma warning disable CS8500 -#pragma warning disable CS8981 -using System; -using System.Runtime.InteropServices; - - -namespace Sails.ClientGenerator -{ - internal static unsafe partial class NativeMethods - { - const string __DllName = "sails_net_client_gen"; - - - - /// - /// # Safety - /// - /// Function [`free_c_string`] should be called after this function - /// - [DllImport(__DllName, EntryPoint = "generate_dotnet_client", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern byte* generate_dotnet_client(byte* program_utf8, int program_len, byte* config_utf8, int config_len); - - /// - /// # Safety - /// - /// This function should not be called before the [`generate_dotnet_client`] - /// - [DllImport(__DllName, EntryPoint = "free_c_string", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - internal static extern void free_c_string(byte* str); - - - } - - - -} diff --git a/net/src/Sails.ClientGenerator/SailsClientGenerator.cs b/net/src/Sails.ClientGenerator/SailsClientGenerator.cs index 4b5dd784..00234881 100644 --- a/net/src/Sails.ClientGenerator/SailsClientGenerator.cs +++ b/net/src/Sails.ClientGenerator/SailsClientGenerator.cs @@ -1,6 +1,4 @@ -#pragma warning disable RS1035 // Do not use APIs banned for analyzers - -using System.Collections.Immutable; +using System.Collections.Immutable; using System.Text; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp;