main.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. mod codegen;
  2. mod docs;
  3. mod public_api;
  4. mod run;
  5. use std::process::Command;
  6. use anyhow::{Context as _, Result};
  7. use cargo_metadata::{Metadata, MetadataCommand};
  8. use clap::Parser;
  9. use xtask::{exec, LIBBPF_DIR};
  10. #[derive(Parser)]
  11. pub struct XtaskOptions {
  12. #[clap(subcommand)]
  13. command: Subcommand,
  14. }
  15. #[derive(Parser)]
  16. enum Subcommand {
  17. Codegen(codegen::Options),
  18. Docs,
  19. IntegrationTest(run::Options),
  20. PublicApi(public_api::Options),
  21. }
  22. fn main() -> Result<()> {
  23. let XtaskOptions { command } = Parser::parse();
  24. let metadata = MetadataCommand::new()
  25. .no_deps()
  26. .exec()
  27. .context("failed to run cargo metadata")?;
  28. let Metadata { workspace_root, .. } = &metadata;
  29. // Initialize the submodules.
  30. exec(Command::new("git").arg("-C").arg(workspace_root).args([
  31. "submodule",
  32. "update",
  33. "--init",
  34. ]))?;
  35. let libbpf_dir = workspace_root.join(LIBBPF_DIR);
  36. let libbpf_dir = libbpf_dir.as_std_path();
  37. match command {
  38. Subcommand::Codegen(opts) => codegen::codegen(opts, libbpf_dir),
  39. Subcommand::Docs => docs::docs(metadata),
  40. Subcommand::IntegrationTest(opts) => run::run(opts),
  41. Subcommand::PublicApi(opts) => public_api::public_api(opts, metadata),
  42. }
  43. }