summaryrefslogtreecommitdiffstats
path: root/tools/wasi-headers/src/main.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /tools/wasi-headers/src/main.rs
parentInitial commit. (diff)
downloadwasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz
wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tools/wasi-headers/src/main.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/wasi-headers/src/main.rs b/tools/wasi-headers/src/main.rs
new file mode 100644
index 0000000..867c31d
--- /dev/null
+++ b/tools/wasi-headers/src/main.rs
@@ -0,0 +1,61 @@
+#[macro_use]
+extern crate clap;
+
+use anyhow::Result;
+use clap::{Arg, SubCommand};
+use std::fs;
+use std::path::Path;
+use wasi_headers::{generate, libc_wasi_api_header, libc_wasi_api_source, snapshot_witx_files};
+
+pub fn run(
+ inputs: &[impl AsRef<Path>],
+ header_output: impl AsRef<Path>,
+ source_output: impl AsRef<Path>,
+) -> Result<()> {
+ let c_header = generate(inputs)?;
+ fs::write(header_output, c_header.header)?;
+ fs::write(source_output, c_header.source)?;
+ Ok(())
+}
+
+fn main() -> Result<()> {
+ let matches = app_from_crate!()
+ .setting(clap::AppSettings::SubcommandRequiredElseHelp)
+ .subcommand(
+ SubCommand::with_name("generate")
+ .arg(Arg::with_name("inputs").required(true).multiple(true))
+ .arg(
+ Arg::with_name("output")
+ .short("o")
+ .long("output")
+ .takes_value(true)
+ .required(true),
+ ),
+ )
+ .subcommand(
+ SubCommand::with_name("generate-libc")
+ .about("generate libc api.h from current snapshot"),
+ )
+ .get_matches();
+
+ if matches.subcommand_matches("generate-libc").is_some() {
+ let inputs = snapshot_witx_files()?;
+ run(&inputs, libc_wasi_api_header(), libc_wasi_api_source())?;
+ } else if let Some(generate) = matches.subcommand_matches("generate") {
+ let inputs = generate
+ .values_of("inputs")
+ .expect("required inputs arg")
+ .collect::<Vec<_>>();
+ let output = generate.value_of("output").expect("required output arg");
+ let output = Path::new(&output);
+ run(
+ &inputs,
+ output.with_extension("h"),
+ output.with_extension("c"),
+ )?;
+ } else {
+ unreachable!("a subcommand must be provided")
+ };
+
+ Ok(())
+}