swift-rs
Call Swift functions from Rust with ease!
Todo
- Swift class deallocation from rust (implementing Drop and using deallocate_{type} methods)
- More ease of use and utility functions
Call Swift functions from Rust with ease!
After looking over swift-bindgen's code, it seems that it's possible to manually alter ARC counts for arbitrary pointers, meaning that it should be possible to let the swift runtime know when rust is done with an SRObject by decrementing the corresponding ARC. This should avoid memory leaks that I believe exist at the moment, since I don't thing swift knows when rust is finished with a value.
How do I handle nil returned from a swift function?
The *const
pointer in SRObject
is private, so I can't check result.0.is_null()
. Any other option?
EDIT: Opened a PR: #5
The rest of the ecosystem mostly uses dual licensing under MIT + Apache, and so does the Rust project. See this issue as an example, and for steps on how to do it.
Should you choose to do it, you have the permission from me: I license past and future contributions to this project under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.
Hey, just been wandering here and there when i landed on this project. This questions is out of pure curiosity as I am mostly a jr. programmer but rust<->swift interoperability looks like kind of exotic thing. I see that for both rust and swift its important to have access to the legacy of c world, but what are I some potential real world scenarios where swift-rust interop is a thing?
Just to make things clear - I am genuinely asking and appreciate the work done on this project!
Currently, string concatenation is used to determine the path to be output for cargo:rustc-link-search=native=
, as seen here:
https://github.com/Brendonovich/swift-rs/blob/1ca64300e3deedbd47d782d86770d5fc673ffaa4/src-rs/build.rs#L80
So if the package_root
argument to link_swift_package
does not end with a /
, the build breaks, and it's not obvious to the user why that has happened.
This needs to be changed to use std::path
's join
mechanism instead of a simple string concatenation.
Currently, there's a build failure when link_swift_package()
is called with package_root
not ending in /
. This happens because cargo:rustc-link-search
is determined using string concatenation. This PR modifies it to use std::path
join
methods instead.
When trying to test this change, I realised that there were the following other miscellaneous issues, which I've fixed as well:
Cargo.lock
. This file is supposed to be committed to repo only by end binaries. Given that this crate is a library, it shouldn't be having this.cargo test
now works.cargo build
and cargo test
on every push to master
branch, and for PRs.crates.io
, license
and build status
badges in README header. The build status would start working only after you've merged this PR.rustfmt
and clippy
.Thank you for this useful crate.
The version of Swift running on my M1 MacBook Pro does not output a runtime compatibility version string which causes the unwrap to fail in the build script. This small change should fix the issue but I am not sure how it will act on other systems so further testing is certainly required. Also removed native and static declarations as those also caused issues with my system.
Output of swift -version
on my system
swift-driver version: 1.26.9 Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6) Target: arm64-apple-macosx12.0
Hello. I'm making a Rust program that uses Swift libraries and developing it in a Linux environment (WSL2). Do you know if this binding library works in Linux environments, or not? Thank you in advance.
Changes:
swift-rs
now supports macOS 10.10 (OS X Yosemite) or higherbuild::link_swift
takes an argument for the minimum macOS version. Eg. build::link_swift("10.10");
Closes #3
See downstream issue for more details: https://github.com/tauri-apps/tauri/issues/4314
In theory, I think the memory management mechanism being used on the Swift side is the issue.
https://github.com/Brendonovich/swift-rs/blob/1c309f652428ecc549fbe8eaccba4835a97d3aa8/src-swift/lib.swift#L66-L69
It seems like memory is being freed twice.
NSObject
values are now supported (#4)build_utils
to build
and is behind corresponding Cargo feature (avoids requiring serde
and serde_json
to be included by default)serde
getMounts
example no longer leaks huge amounts of memoryMechanica A library of Swift utils to ease your iOS, macOS, watchOS, tvOS and Linux development. Requirements Documentation Installation License Contr
Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload
ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti
Indecipherable symbols that some people claim have actual meaning. Please see the documentation for installation instructions. What's included? Import
SwiftTools This is a set of tools written in Swift that add some sugar and some small functionality. Mainly meant for small projects and scripts, as a
SwiftSortUtils Motivation This library takes a shot at making comparing and sorting in Swift more pleasant. It also allows you to reuse your old NSSor
Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way
Outlets Utility functions for validating IBOutlet and IBAction connections. About Outlets provides a set of functions which validate that IBOutlets ar
DGLabelSize Functions that calculate the size of uilabel based on different stri
BCSwiftTor Opinionated pure Swift controller for Tor, including full support for
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum
SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in
Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생
swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest
__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.
SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu
Swift When - supporting switch expressions in Swift! What is it? Basically, it a
swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea