-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit * Added platform enum * Added test * Added XCFramework generation * Added Swift Package generation * Added import PackageDescription to generated Package.swift * update gitignore and Cargo.toml * Removed generated files from git * Minor fixes in Package generation * fixed gen_package test * Finished gen_package test * Code cleanup * rename of test file * minor edit * removed note in book It turns out the library tags order is not important after all, so I have removed it. * added build script to test Fixed test failing with error "Couldn't copy SwiftBirdgeCore header file". This was due to the build.sh not being executed. * added create generated folder * updated relevant book chapter * removed simulator target from test * Added post-build to book chapter * removed println output of xcodebuild * rename test projects * update workspace members to reflect new name * debug for actions * removed iOS targets from test This is likely the reason the tests are failing, because these targets are not present in GitHub Actions * added target to test.yml * transform to temp dir * made init func public This is needed when accessing the init when depending on the Swift package. Otherwise the init can't be used. * rename test-swift-packages * update book chapter * rename generate to create * rename ApplePlatform variants to use Rust naming conventions * test modifications - Added deletion of previously generated files - Added publish = false to Cargo.toml of test package - Added THISDIR trick to build script * Hello Rust! > Hello, From Rust * using tempfile crate for tempdir * cargo fmt * remove post-build from build instruction * moved Swift Package test to integration-tests * code cleanup * rm echo
- Loading branch information
Showing
26 changed files
with
516 additions
and
156 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
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
10 changes: 10 additions & 0 deletions
10
SwiftRustIntegrationTestRunner/integration-test-create-swift-package/Cargo.toml
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,10 @@ | ||
[package] | ||
name = "integration-test-create-swift-package" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
swift-bridge-build = { path = "../../crates/swift-bridge-build" } |
18 changes: 18 additions & 0 deletions
18
SwiftRustIntegrationTestRunner/integration-test-create-swift-package/src/main.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,18 @@ | ||
use std::collections::HashMap; | ||
use std::path::Path; | ||
|
||
use swift_bridge_build::ApplePlatform as Platform; | ||
use swift_bridge_build::{create_package, CreatePackageConfig}; | ||
|
||
// TODO: paths | ||
fn main() { | ||
// Generate package | ||
create_package(CreatePackageConfig { | ||
bridge_dir: &Path::new("swift-package-rust-library-fixture/generated"), | ||
paths: HashMap::from([ | ||
(Platform::MacOS, &Path::new("swift-package-rust-library-fixture/target/x86_64-apple-darwin/debug/libtest_swift_packages.a") as _), | ||
]), | ||
out_dir: &Path::new("swift-package-rust-library-fixture/MySwiftPackage"), | ||
package_name: "MySwiftPackage" | ||
}); | ||
} |
4 changes: 4 additions & 0 deletions
4
SwiftRustIntegrationTestRunner/swift-package-rust-library-fixture/.gitignore
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,4 @@ | ||
target/ | ||
package/ | ||
generated/ | ||
MySwiftPackage |
16 changes: 16 additions & 0 deletions
16
SwiftRustIntegrationTestRunner/swift-package-rust-library-fixture/Cargo.toml
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,16 @@ | ||
[package] | ||
name = "test-swift-packages" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
|
||
[build-dependencies] | ||
swift-bridge-build = { path = "../../crates/swift-bridge-build" } | ||
|
||
[dependencies] | ||
swift-bridge = { path = "../.." } |
13 changes: 13 additions & 0 deletions
13
SwiftRustIntegrationTestRunner/swift-package-rust-library-fixture/build.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,13 @@ | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let out_dir = PathBuf::from("./generated"); | ||
|
||
let bridges = vec!["src/lib.rs"]; | ||
for path in &bridges { | ||
println!("cargo:rerun-if-changed={}", path); | ||
} | ||
|
||
swift_bridge_build::parse_bridges(bridges) | ||
.write_all_concatenated(out_dir, env!("CARGO_PKG_NAME")); | ||
} |
8 changes: 8 additions & 0 deletions
8
SwiftRustIntegrationTestRunner/swift-package-rust-library-fixture/build.sh
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,8 @@ | ||
#!/usr/bin/env bash | ||
|
||
THIS_DIR=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) | ||
ROOT_DIR="$THIS_DIR" | ||
cd $ROOT_DIR | ||
|
||
export SWIFT_BRIDGE_OUT_DIR="$(pwd)/generated" | ||
cargo build --target x86_64-apple-darwin --target-dir "$(pwd)/target" |
10 changes: 10 additions & 0 deletions
10
SwiftRustIntegrationTestRunner/swift-package-rust-library-fixture/src/lib.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,10 @@ | ||
#[swift_bridge::bridge] | ||
mod ffi { | ||
extern "Rust" { | ||
fn hello_rust() -> String; | ||
} | ||
} | ||
|
||
fn hello_rust() -> String { | ||
String::from("Hello, From Rust!") | ||
} |
7 changes: 7 additions & 0 deletions
7
SwiftRustIntegrationTestRunner/swift-package-test-package/.gitignore
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,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
23 changes: 23 additions & 0 deletions
23
SwiftRustIntegrationTestRunner/swift-package-test-package/Package.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,23 @@ | ||
// swift-tools-version:5.5 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "swift-package-test-package", | ||
products: [ | ||
.library( | ||
name: "swift-package-test-package", | ||
targets: ["swift-package-test-package"]), | ||
], | ||
dependencies: [ | ||
.package(path: "../swift-package-rust-library-fixture/MySwiftPackage") | ||
], | ||
targets: [ | ||
.target( | ||
name: "swift-package-test-package", | ||
dependencies: []), | ||
.testTarget( | ||
name: "swift-package-test-packageTests", | ||
dependencies: ["swift-package-test-package", "MySwiftPackage"]), | ||
] | ||
) |
1 change: 1 addition & 0 deletions
1
...-package-test-package/Sources/swift-package-test-package/swift_package_test_package.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 @@ | ||
|
9 changes: 9 additions & 0 deletions
9
...-test-package/Tests/swift-package-test-packageTests/swift_package_test_packageTests.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,9 @@ | ||
import XCTest | ||
import MySwiftPackage | ||
@testable import swift_package_test_package | ||
|
||
final class swift_package_test_packageTests: XCTestCase { | ||
func testPackageRun() throws { | ||
XCTAssertEqual("Hello, From Rust!", hello_rust().toString()) | ||
} | ||
} |
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
Oops, something went wrong.