Skip to content

Commit

Permalink
Merge modulemaps, setup test case for multi-crate project
Browse files Browse the repository at this point in the history
  • Loading branch information
KingOfDog committed Apr 8, 2024
1 parent 093bccb commit 012c920
Show file tree
Hide file tree
Showing 18 changed files with 617 additions and 21 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Examples

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always
Expand All @@ -13,23 +13,25 @@ jobs:
tests:
strategy:
matrix:
path: [
'./swift-examples/hello-world/greeter',
'./swift-examples/hello-world-macro/greeter'
path:
[
"./swift-examples/hello-world/greeter",
"./swift-examples/hello-world-macro/greeter",
"./swift-examples/hello-world-macro-multi-crate/greeter",
]
target: [
'platform=macOS,arch=x86_64',
'generic/platform=iOS',
"platform=macOS,arch=x86_64",
"generic/platform=iOS",
# 'platform=iOS Simulator,os=latest'
]
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install
run: cargo install --force --path .
- name: Build example libraries
working-directory: ${{ matrix.path }}
run: cargo swift package --accept-all
- name: Build example apps
working-directory: ${{ matrix.path }}/../app
run: xcodebuild -scheme App -destination "${{ matrix.target }}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- uses: actions/checkout@v4
- name: Install
run: cargo install --force --path .
- name: Build example libraries
working-directory: ${{ matrix.path }}
run: cargo swift package --accept-all
- name: Build example apps
working-directory: ${{ matrix.path }}/../app
run: xcodebuild -scheme App -destination "${{ matrix.target }}" CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
19 changes: 14 additions & 5 deletions src/bindings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::fs::{self, create_dir};
use std::{
fs::{self, create_dir},
io,
};

use crate::Result;
use camino::Utf8Path;
Expand Down Expand Up @@ -28,6 +31,11 @@ pub fn generate_bindings(lib_path: &Utf8Path) -> Result<()> {
false,
)?;

let mut modulemap = fs::OpenOptions::new()
.create(true)
.append(true)
.open(headers.join("module.modulemap"))?;

for output in uniffi_outputs {
let crate_name = output.crate_name;
fs::copy(
Expand All @@ -40,10 +48,11 @@ pub fn generate_bindings(lib_path: &Utf8Path) -> Result<()> {
out_dir.join(format!("{ffi_name}.h")),
headers.join(format!("{ffi_name}.h")),
)?;
fs::copy(
out_dir.join(format!("{ffi_name}.modulemap")),
headers.join(format!("{ffi_name}.modulemap")),
)?;

let mut modulemap_part = fs::OpenOptions::new()
.read(true)
.open(out_dir.join(format!("{ffi_name}.modulemap")))?;
io::copy(&mut modulemap_part, &mut modulemap)?;
}

Ok(())
Expand Down
3 changes: 3 additions & 0 deletions swift-examples/hello-world-macro-multi-crate/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/xcuserdata/
.DS_Store
build/
Loading

0 comments on commit 012c920

Please sign in to comment.