Skip to content
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

Update Swift example #6821

Closed
wants to merge 1 commit into from
Closed

Update Swift example #6821

wants to merge 1 commit into from

Conversation

TeamPuzel
Copy link

Hi! I was browsing the examples and noticed that Swift needed some love. The language improved a lot for low level use cases since this example was written and I thought I"d make it more up to date 🙂

  • Converted the example to pure Swift
    • removed the C header thanks to extern support
    • Removed Foundation. It is not portable and unavailable in embedded mode. Creating Swift strings now writes String memory directly, instead of using a complicated objc-bridged data structure.
    • Used naming conventions idiomatic to the language (count vs length etc)
    • Removed free functions in favor of methods and computed properties
  • Used the new embedded mode to make binaries portable, tiny, faster and easier to link with
  • Used native Swift allocation APIs instead of using libc directly, which is more portable and doesn"t require importing anything.
  • Removed return keywords in single expression functions
  • Used native pointer types instead of integers

Is there somewhere else I have to modify to build using the new flags?

Where can I find any resources/documentation I"d need if I wanted to implement a library for seamless Swift/Roc integration? I saw that Rust and Zig have some "glue" code but Swift does not appear to, it would be fun to write if that"s useful 🙂

@lukewilliamboswell
Copy link
Collaborator

Oh cool. I need to check this out.

I started a template repository to help people get started, but my swift knowledge is lacking.

https://github.com/lukewilliamboswell/roc-platform-template-swift

@lukewilliamboswell
Copy link
Collaborator

If you"re interested in Swift glue, I"d love to help you get started. DM me on zulip maybe would be best.

I started this repository to try and organise glue better.

https://github.com/lukewilliamboswell/roc-glue-code-gen


// SAFETY: Not valid for small strings
private var data: UnsafeBufferPointer<UInt8> {
assert(isSmallString) // Assert this in debug builds
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this, it should be assert(!isSmallString), now it accidentally crashes correct code

@TeamPuzel
Copy link
Author

If you"re interested in Swift glue, I"d love to help you get started. DM me on zulip maybe would be best.

Sure, I"ll do that tomorrow 👍🏻

Copy link

Thank you for your contribution! Sometimes PRs end up staying open for a long time without activity, which can make the list of open PRs get long and time-consuming to review. To keep things manageable for reviewers, this bot automatically closes PRs that haven’t had activity in 60 days. This PR hasn’t had activity in 30 days, so it will be automatically closed if there is no more activity in the next 30 days. Keep in mind that PRs marked Closed are not deleted, so no matter what, the PR will still be right here in the repo. You can always access it and reopen it anytime you like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants