{"id":14992024,"url":"https://github.com/Deukhoofd/csharp_binder","last_synced_at":"2025-09-25T14:30:41.597Z","repository":{"id":57614183,"uuid":"336636905","full_name":"Deukhoofd/csharp_binder","owner":"Deukhoofd","description":"A simple library to generate C# bindings for a Rust foreign function interface (FFI)","archived":false,"fork":false,"pushed_at":"2021-02-15T16:56:18.000Z","size":92,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T02:19:16.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Deukhoofd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-06T21:08:59.000Z","updated_at":"2025-06-08T12:26:17.000Z","dependencies_parsed_at":"2022-09-10T08:50:30.670Z","dependency_job_id":null,"html_url":"https://github.com/Deukhoofd/csharp_binder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Deukhoofd/csharp_binder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deukhoofd%2Fcsharp_binder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deukhoofd%2Fcsharp_binder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deukhoofd%2Fcsharp_binder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deukhoofd%2Fcsharp_binder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Deukhoofd","download_url":"https://codeload.github.com/Deukhoofd/csharp_binder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Deukhoofd%2Fcsharp_binder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276932065,"owners_count":25730715,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-25T02:00:09.612Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T15:00:39.482Z","updated_at":"2025-09-25T14:30:41.284Z","avatar_url":"https://github.com/Deukhoofd.png","language":"Rust","funding_links":[],"categories":["FFI Bindings"],"sub_categories":[],"readme":"[![crates.io](https://img.shields.io/crates/v/csharp_binder.svg)](https://crates.io/crates/csharp_binder)\n\n## CSharp_Binder\n\nCSharp_Binder is a tool written to generate C# bindings for a Rust FFI (Foreign Function Interface).\nBy interacting over extern C functions, this allows you to easily call Rust functions from C#,\nwithout having to write the extern C# functions yourself.\n\nCSharp_Binder will when given a Rust script, parse this script, and extract any functions marked as\nextern \"C\", enums with a ``[repr(u*)]`` attribute, and structs with a ``#[repr(C)]`` attribute. It\nwill then convert these into appropriate representations in C#.\n\nCSharp_Binder will also extract Rust documentation on functions, enums and their variants, and\non structs and their fields, and convert it into XML Documentation on the generated C# code.\n\nNote that CSharp_Binder uses syn to parse Rust scripts, so macros will not be expanded! If you\nhave functions, structs, or enums that need to be extracted inside macros, make sure to run them\nto something like cargo-expand first.\n\n## Examples\n\nExample:\n```rust\nuse csharp_binder::{CSharpConfiguration, CSharpBuilder};\n\nfn main(){\n    // Create C# configuration with C# target version 9.\n    let mut configuration = CSharpConfiguration::new(9);\n    let rust_file = r#\"\n    /// Just a random return enum\n    #[repr(u8)]\n    enum ReturnEnum {\n        Val1,\n        Val2,\n    }\n\n    /// An input struct we expect\n    #[repr(C)]\n    struct InputStruct {\n        field_a: u16,\n        /// This field is used for floats!\n        field_b: f64,\n    }\n\n    pub extern \"C\" fn foo(a: InputStruct) -\u003e ReturnEnum {\n    }\n    \"#;\n    let mut builder = CSharpBuilder::new(rust_file, \"foo\", \u0026mut configuration)\n                        .expect(\"Failed to parse file\");\n    builder.set_namespace(\"MainNamespace\");\n    builder.set_type(\"InsideClass\");\n    let script = builder.build().expect(\"Failed to build\");\n}\n```\n\nThis would return the following C# code:\n\n```cs\n// Automatically generated, do not edit!\nusing System;\nusing System.Runtime.InteropServices;\n\nnamespace MainNamespace\n{\n   internal static class InsideClass\n   {\n       /// \u003csummary\u003e\n       /// Just a random return enum\n       /// \u003c/summary\u003e\n        public enum ReturnEnum : byte\n        {\n            Val1,\n            Val2,\n        }\n\n        /// \u003csummary\u003e\n        /// An input struct we expect\n        /// \u003c/summary\u003e\n        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]\n        public struct InputStruct\n        {\n            /// \u003cremarks\u003eu16\u003c/remarks\u003e\n            public ushort FieldA { get; init; }\n            /// \u003csummary\u003e\n            /// This field is used for floats!\n            /// \u003c/summary\u003e\n            /// \u003cremarks\u003ef64\u003c/remarks\u003e\n            public double FieldB { get; init; }\n\n            public InputStruct(ushort fieldA, double fieldB)\n            {\n                FieldA = fieldA;\n                FieldB = fieldB;\n            }\n        }\n\n        /// \u003cparam name=\"a\"\u003eInputStruct\u003c/param\u003e\n        /// \u003creturns\u003eReturnEnum\u003c/returns\u003e\n        [DllImport(\"foo\", CallingConvention = CallingConvention.Cdecl, EntryPoint=\"foo\")]\n        internal static extern ReturnEnum Foo(InputStruct a);\n\n    }\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeukhoofd%2Fcsharp_binder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDeukhoofd%2Fcsharp_binder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDeukhoofd%2Fcsharp_binder/lists"}