Skip to content

Commit

Permalink
Add multi-platform example to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jun 23, 2024
1 parent 809c6ee commit 921ac2d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ env:
jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- name: rustup target add
run: rustup target add aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios
- name: Build
run: cargo build --verbose
test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: jdx/mise-action@v2
with:
mise_toml: |
[tools]
tuist = "4.17.0"
- name: Run tests
run: cargo test --verbose
fmt_and_clippy:
Expand Down
64 changes: 64 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,62 @@ fn end_to_end_dynamic() {
assert_eq!("MyMath.rust_add(4 + 2) = 6\n", output);
}

#[test]
fn multi_platform_static() {
let out_dir = create_output_dir("multi-platform-static");
let target_dir = out_dir.join("mymath-lib/target");
fs::create_dir_all(&target_dir).unwrap();
let cli = XcCli::parse_from([
"cargo-xcframework",
"--manifest-path=examples/multi-platform/mymath-lib/Cargo.toml",
"--lib-type=staticlib",
"--target-dir",
target_dir.to_str().unwrap(),
]);
let produced = xcframework::build(cli).unwrap();
assert_eq!(produced.module_name, "MyMath");
let tuist_workspace_dir = cp_tuist_workspace(out_dir.as_path()).unwrap();
let cmd = Command::new("mise")
.current_dir(&tuist_workspace_dir)
.args(["x", "--"])
.args(["tuist", "test"])
.output()
.unwrap();
assert!(cmd.status.success());
if !cmd.status.success() {
eprintln!("{}", String::from_utf8_lossy(&cmd.stdout));
eprintln!("{}", String::from_utf8_lossy(&cmd.stderr));
}
}

#[test]
fn multi_platform_dynamic() {
let out_dir = create_output_dir("multi-platform-dynamic");
let target_dir = out_dir.join("mymath-lib/target");
fs::create_dir_all(&target_dir).unwrap();
let cli = XcCli::parse_from([
"cargo-xcframework",
"--manifest-path=examples/multi-platform/mymath-lib/Cargo.toml",
"--lib-type=cdylib",
"--target-dir",
target_dir.to_str().unwrap(),
]);
let produced = xcframework::build(cli).unwrap();
assert_eq!(produced.module_name, "MyMath");
let tuist_workspace_dir = cp_tuist_workspace(out_dir.as_path()).unwrap();
let cmd = Command::new("mise")
.current_dir(&tuist_workspace_dir)
.args(["x", "--"])
.args(["tuist", "test"])
.output()
.unwrap();
assert!(cmd.status.success());
if !cmd.status.success() {
eprintln!("{}", String::from_utf8_lossy(&cmd.stdout));
eprintln!("{}", String::from_utf8_lossy(&cmd.stderr));
}
}

fn cp_swift_exe(dest: &Path) -> Result<Utf8PathBuf> {
let from = Utf8PathBuf::from("examples/end-to-end/swift-exe");

Expand All @@ -114,3 +170,11 @@ fn cp_swift_exe(dest: &Path) -> Result<Utf8PathBuf> {
}
Ok(dest.join("swift-exe"))
}

fn cp_tuist_workspace(dest: &Path) -> Result<Utf8PathBuf> {
let from = Utf8PathBuf::from("examples/multi-platform/tuist-workspace");
let dest = Utf8PathBuf::from_path_buf(dest.to_path_buf()).unwrap();
dest.create_dir_all_if_needed()?;
fs_extra::dir::copy(from, &dest, &fs_extra::dir::CopyOptions::new())?;
Ok(dest.join("tuist-workspace"))
}

0 comments on commit 921ac2d

Please sign in to comment.