-
Notifications
You must be signed in to change notification settings - Fork 64
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
Document how to use Swift Packages on Linux #313
base: master
Are you sure you want to change the base?
Document how to use Swift Packages on Linux #313
Conversation
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.
Thanks for working on this.
I left some minor feedback around fleshing out the section a bit more.
After that looks good to me and we can land this.
* this ensures that the flags that are normally passed via swiftc are forwarded during swift-build | ||
* Since the path of the resulting rust library "target/debug" depends on the build type, you can set a global variable like this: | ||
```swift | ||
#if DEBUG | ||
let buildType = "debug" | ||
#else | ||
let buildType = "release" | ||
#endif | ||
``` |
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.
Where is this global variable set?
linkerSettings: [ | ||
.unsafeFlags([ | ||
"generated/SwiftBridgeCore.swift", "generated/proj-rs/proj-rs.swift", | ||
"-import-objc-header", "bridging-header.h", "-Ltarget/debug", "-lcorpus", |
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.
Can we change this example so that it supports both debug and release builds
linkerSettings: [ | ||
.unsafeFlags([ | ||
"generated/SwiftBridgeCore.swift", "generated/proj-rs/proj-rs.swift", | ||
"-import-objc-header", "bridging-header.h", "-Ltarget/debug", "-lcorpus", |
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.
Let's explain what this -lcorpus
flag does
* Set up swift-bridge according to the guide (see chapter "swiftc and cargo") | ||
* Link against swift-bridge and your library, like the one below: | ||
```swift | ||
targets: [ |
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.
Let's paste a complete file, unless there are so many lines that it's hard to understand.
This helps the reader better orient themselves towards what they're looking at.
Also, say what this file is. Explicitly say that this is a Package.swift
i.e. "like the Package.swift
file below:"
# Usage on Linux | ||
Usage on Linux is a little bit different than on macOS. This guide will help you set up SwiftPM and Cargo. The general workflow is: | ||
* Set up Package.swift so that "cargo build" is called (You can use something like this here: "https://stackoverflow.com/questions/26971240/how-do-i-run-a-terminal-command-in-a-swift-script-e-g-xcodebuild" to invoke cargo during a swift build) | ||
* Set up swift-bridge according to the guide (see chapter "swiftc and cargo") |
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.
Set up swift-bridge
how? What does the user need to do? Everything in the guide? A couple things in the guide? Can be more explicit here.
|
||
# Usage on Linux | ||
Usage on Linux is a little bit different than on macOS. This guide will help you set up SwiftPM and Cargo. The general workflow is: | ||
* Set up Package.swift so that "cargo build" is called (You can use something like this here: "https://stackoverflow.com/questions/26971240/how-do-i-run-a-terminal-command-in-a-swift-script-e-g-xcodebuild" to invoke cargo during a swift build) |
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.
Let's not depend on external sources.
Users should not need to hop around other links/sites/pages to figure out how this works, unless inlining the information is undesirable for some reason.
Let's instead just inline an example of what you mean here, vs. making the user go find and interpret a stackoverflow page.
@@ -238,3 +233,38 @@ cd SwiftProject | |||
swift run | |||
# You should see "Hello from Rust!" in your terminal. | |||
``` | |||
|
|||
# Usage on Linux | |||
Usage on Linux is a little bit different than on macOS. This guide will help you set up SwiftPM and Cargo. The general workflow is: |
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.
Let's explicitly mention the ways that it is different.
So, up here instead of saying it's "a little bit different" just summarize the main way(s) that it is different.
Then your guide below walks the user through addressing those differences.
I just opened an issue about generating a (linux-compatible) SPM package: #315 |
FWIW, I tried this approach for the new testing harness, but I couldn't get it working. Package.swift: import PackageDescription
let package = Package(
name: "IntegrationTests",
targets: [
.target(
name: "Fixtures",
swiftSettings: [
.interoperabilityMode(.C),
.unsafeFlags([
"-import-objc-header", "Sources/Fixtures/bridge.h",
])
],
linkerSettings: [
// Link our rust static library...
.linkedLibrary("rust_fixtures"),
// And tell the linker where to look for it.
.unsafeFlags(["-L../target/debug"]),
]
),
.testTarget(
name: "Tests",
dependencies: ["Fixtures"]
)
]
) Sample output of
|
No description provided.