-
Notifications
You must be signed in to change notification settings - Fork 63
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
Swift Vec<primitive>
Return Type and Function Argument
#229
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ed5db94
Adjust IR representation
timwedde 6dd5183
Add codegen tests
timwedde ebcabd7
Add integration tests
timwedde 2325ab9
Remove autogenerated file header comment
timwedde c1e3f0b
Use more appropriate string comparison function
timwedde dcef8a8
Use more descriptive function names in integration tests
timwedde c592c1a
Assure Vec values in Swift using asserts
timwedde 5dd4a48
Use more appropriate string comparison function (again)
timwedde f5fe768
Call test function from the Swift side as well
timwedde 9d9abd0
`cargo fmt` run
timwedde File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Vec.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,17 @@ | ||
import Foundation | ||
|
||
func swift_arg_vec_u8(vec _: RustVec<UInt8>) { | ||
assert(vec[0] == 1) | ||
assert(vec[1] == 2) | ||
assert(vec[2] == 3) | ||
assert(vec[3] == 4) | ||
assert(vec[4] == 5) | ||
} | ||
|
||
func swift_return_vec_u8() -> RustVec<UInt8> { | ||
let vec = RustVec<UInt8>() | ||
for i in 0 ... 4 { | ||
vec.push(value: UInt8(i)) | ||
} | ||
return vec | ||
} |
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 |
---|---|---|
|
@@ -25,6 +25,28 @@ mod ffi { | |
arg: Vec<TransparentEnumInsideVecT>, | ||
) -> Vec<TransparentEnumInsideVecT>; | ||
} | ||
|
||
extern "Rust" { | ||
fn run_vec_tests(); | ||
} | ||
|
||
extern "Swift" { | ||
fn swift_return_vec_u8() -> Vec<u8>; | ||
fn swift_arg_vec_u8(vec: Vec<u8>); | ||
} | ||
} | ||
|
||
fn run_vec_tests() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice |
||
let vec = ffi::swift_return_vec_u8(); | ||
assert_eq!(vec.len(), 5); | ||
assert_eq!(vec[0], 0); | ||
assert_eq!(vec[1], 1); | ||
assert_eq!(vec[2], 2); | ||
assert_eq!(vec[3], 3); | ||
assert_eq!(vec[4], 4); | ||
|
||
let vec: Vec<u8> = vec![1, 2, 3, 4, 5]; | ||
ffi::swift_arg_vec_u8(vec); | ||
} | ||
|
||
pub struct ARustTypeInsideVecT { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to call this on the Swift side in
VecTests.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/chinedufn/swift-bridge/blob/master/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/VecTests.swift#L11
something like: