oo_bindgen/cli/
args.rs

1use clap::Parser;
2use platforms::Platform;
3use std::collections::HashMap;
4use std::path::PathBuf;
5
6impl Args {
7    pub(crate) fn get() -> Self {
8        let mut args = Args::parse();
9        if !(args.build_c || args.build_dotnet || args.build_java) {
10            args.build_c = true;
11            args.build_dotnet = true;
12            args.build_java = true;
13        }
14        args
15    }
16}
17
18use crate::backend::dotnet::TargetFramework;
19use serde::Deserialize;
20
21#[derive(Deserialize)]
22pub(crate) struct EnabledLanguages {
23    pub(crate) cpp: bool,
24    pub(crate) dotnet: bool,
25    pub(crate) java: bool,
26}
27
28#[derive(Deserialize)]
29pub(crate) struct PackageOptions {
30    /// This limits which available target platforms are packaged for each language
31    targets: HashMap<String, EnabledLanguages>,
32}
33
34impl PackageOptions {
35    pub(crate) fn package_dotnet(&self, platform: &Platform) -> bool {
36        self.targets
37            .get(platform.target_triple)
38            .map(|x| x.dotnet)
39            .unwrap_or(false)
40    }
41
42    pub(crate) fn package_cpp(&self, platform: &Platform) -> bool {
43        self.targets
44            .get(platform.target_triple)
45            .map(|x| x.cpp)
46            .unwrap_or(false)
47    }
48
49    pub(crate) fn package_java(&self, platform: &Platform) -> bool {
50        self.targets
51            .get(platform.target_triple)
52            .map(|x| x.java)
53            .unwrap_or(false)
54    }
55}
56
57#[derive(Parser)]
58#[command(author, version, about, long_about = None)]
59pub(crate) struct Args {
60    /// build the C bindings
61    #[arg(long = "c", default_value_t = false)]
62    pub(crate) build_c: bool,
63    /// build the .NET bindings
64    #[arg(long = "dotnet", default_value_t = false)]
65    pub(crate) build_dotnet: bool,
66    /// build the Java bindings
67    #[arg(long = "java", default_value_t = false)]
68    pub(crate) build_java: bool,
69    /// Path to where the compiled FFI/JNI shared libraries reside or a directory with multiple target triple dirs if packaging.
70    /// If not specified, ./release/target is assumed
71    #[arg(long = "artifact-dir", short = 'a')]
72    pub(crate) artifact_dir: Option<PathBuf>,
73    /// Target triple to use to lookup the platform for generation, otherwise assume the HOST platform.
74    #[arg(long = "target", short = 'r')]
75    pub(crate) target_triple: Option<String>,
76    /// Target .NET framework, which indirectly determines the C# language version
77    #[arg(value_enum, short = 't', long = "target-dotnet-framework", default_value_t = TargetFramework::NetStandard2_0)]
78    pub(crate) target_framework: TargetFramework,
79    /// generate doxygen documentation
80    #[arg(long = "doxygen", default_value_t = false)]
81    pub(crate) generate_doxygen: bool,
82    /// do NOT run the unit tests
83    #[arg(long = "no-tests", default_value_t = false)]
84    pub(crate) no_tests: bool,
85    /// Generate package from the provided directory
86    #[arg(long = "package", short = 'k')]
87    pub(crate) package_dir: Option<PathBuf>,
88    /// Generate package(s) with the following options file
89    #[arg(long = "options", short = 'o')]
90    pub(crate) package_options: Option<PathBuf>,
91    /// Path(s) to extra files to include in the generated bindings
92    #[arg(short = 'f', long = "extra-files")]
93    pub(crate) extra_files: Vec<PathBuf>,
94}