-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make enums support the
swift_name
attrib (#126)
This commit makes enums support the `swift_name` attribute, which lets you choose the name that shows up on the Swift side. For example, the following is now possible: ```rust #[swift_bridge::bridge] mod ffi { #[swift_bridge(swift_name = "EnumRename")] enum EnumName { Variant1, Variant2, } } ```
- Loading branch information
Showing
11 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/SharedEnumAttributes.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// SharedEnumAttributes.swift | ||
// SwiftRustIntegrationTestRunner | ||
// | ||
// Created by Frankie Nwafili on 12/15/22. | ||
// | ||
|
||
import Foundation | ||
|
||
func extern_swift_enum_rename(arg: EnumRename) -> EnumRename { | ||
arg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod already_declared; | ||
mod swift_name; |
27 changes: 27 additions & 0 deletions
27
crates/swift-integration-tests/src/enum_attributes/swift_name.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/// We declare an enum and rename it using the `swift_name` attribute. | ||
/// We then use them as function arg and return types. | ||
/// | ||
/// Related: crates/swift-bridge-ir/src/codegen/codegen_tests/transparent_enum_codegen_tests.rs | ||
/// - shared_enum_swift_name_attribute | ||
#[swift_bridge::bridge] | ||
mod ffi { | ||
#[swift_bridge(swift_name = "EnumRename")] | ||
enum EnumName { | ||
Variant1, | ||
Variant2, | ||
} | ||
|
||
extern "Rust" { | ||
fn extern_rust_enum_rename(arg: EnumName) -> EnumName; | ||
} | ||
|
||
extern "Swift" { | ||
fn extern_swift_enum_rename(arg: EnumName) -> EnumName; | ||
} | ||
} | ||
|
||
use ffi::EnumName; | ||
|
||
fn extern_rust_enum_rename(arg: EnumName) -> EnumName { | ||
arg | ||
} |