| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
use anyhow::Result; |
| 6 |
use camino::Utf8PathBuf; |
| 7 |
use clap::{Args, Parser}; |
| 8 |
|
| 9 |
use uniffi_bindgen::bindings::{generate_swift_bindings, SwiftBindingsOptions}; |
| 10 |
|
| 11 |
#[derive(Debug, Parser)] |
| 12 |
#[command(version, about, long_about = None)] |
| 13 |
struct Cli { |
| 14 |
#[command(flatten)] |
| 15 |
kinds: Kinds, |
| 16 |
/// Library path to generate bindings for |
| 17 |
library_path: Utf8PathBuf, |
| 18 |
/// Directory to generate files in |
| 19 |
out_dir: Utf8PathBuf, |
| 20 |
/// Generate a XCFramework-compatible modulemap |
| 21 |
#[arg(long)] |
| 22 |
xcframework: bool, |
| 23 |
/// module name for the generated modulemap |
| 24 |
#[arg(long)] |
| 25 |
module_name: Option<String>, |
| 26 |
/// filename for the generate modulemap |
| 27 |
#[arg(long)] |
| 28 |
modulemap_filename: Option<String>, |
| 29 |
/// Whether we should exclude dependencies when running "cargo metadata". |
| 30 |
/// This will mean external types may not be resolved if they are implemented in crates |
| 31 |
/// outside of this workspace. |
| 32 |
/// This can be used in environments when all types are in the namespace and fetching |
| 33 |
/// all sub-dependencies causes obscure platform specific problems. |
| 34 |
#[clap(long)] |
| 35 |
metadata_no_deps: bool, |
| 36 |
/// What frameworks to link against when generating the modulemap file. |
| 37 |
#[arg(long)] |
| 38 |
link_frameworks: Vec<String>, |
| 39 |
} |
| 40 |
|
| 41 |
#[derive(Debug, Args)] |
| 42 |
#[group(required = true, multiple = true)] |
| 43 |
struct Kinds { |
| 44 |
/// Generate swift files |
| 45 |
#[arg(long)] |
| 46 |
swift_sources: bool, |
| 47 |
|
| 48 |
/// Generate header files |
| 49 |
#[arg(long)] |
| 50 |
headers: bool, |
| 51 |
|
| 52 |
/// Generate modulemap |
| 53 |
#[arg(long)] |
| 54 |
modulemap: bool, |
| 55 |
} |
| 56 |
|
| 57 |
pub fn run_main() -> Result<()> { |
| 58 |
let cli = Cli::parse(); |
| 59 |
generate_swift_bindings(cli.into()) |
| 60 |
} |
| 61 |
|
| 62 |
impl From<Cli> for SwiftBindingsOptions { |
| 63 |
fn from(cli: Cli) -> Self { |
| 64 |
Self { |
| 65 |
generate_swift_sources: cli.kinds.swift_sources, |
| 66 |
generate_headers: cli.kinds.headers, |
| 67 |
generate_modulemap: cli.kinds.modulemap, |
| 68 |
library_path: cli.library_path, |
| 69 |
out_dir: cli.out_dir, |
| 70 |
xcframework: cli.xcframework, |
| 71 |
module_name: cli.module_name, |
| 72 |
modulemap_filename: cli.modulemap_filename, |
| 73 |
metadata_no_deps: cli.metadata_no_deps, |
| 74 |
link_frameworks: cli.link_frameworks, |
| 75 |
} |
| 76 |
} |
| 77 |
} |