You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. use eyre::{bail, Context};
  2. use std::path::Path;
  3. #[tokio::main]
  4. async fn main() -> eyre::Result<()> {
  5. let root = Path::new(env!("CARGO_MANIFEST_DIR"));
  6. std::env::set_current_dir(root.join(file!()).parent().unwrap())
  7. .wrap_err("failed to set working dir")?;
  8. tokio::fs::create_dir_all("build").await?;
  9. build_package("cxx-dataflow-example-node-rust-api").await?;
  10. build_package("cxx-dataflow-example-operator-rust-api").await?;
  11. build_package("dora-node-api-c").await?;
  12. build_cxx_node(
  13. root,
  14. &Path::new("node-c-api").join("main.cc").canonicalize()?,
  15. "node_c_api",
  16. )
  17. .await?;
  18. build_cxx_operator(
  19. &Path::new("operator-c-api")
  20. .join("operator.cc")
  21. .canonicalize()?,
  22. "operator_c_api",
  23. )
  24. .await?;
  25. build_package("dora-runtime").await?;
  26. dora_coordinator::run(dora_coordinator::Command::Run {
  27. dataflow: Path::new("dataflow.yml").to_owned(),
  28. runtime: Some(root.join("target").join("release").join("dora-runtime")),
  29. })
  30. .await?;
  31. Ok(())
  32. }
  33. async fn build_package(package: &str) -> eyre::Result<()> {
  34. let cargo = std::env::var("CARGO").unwrap();
  35. let mut cmd = tokio::process::Command::new(&cargo);
  36. cmd.arg("build").arg("--release");
  37. cmd.arg("--package").arg(package);
  38. if !cmd.status().await?.success() {
  39. bail!("failed to build {package}");
  40. };
  41. Ok(())
  42. }
  43. async fn build_cxx_node(root: &Path, path: &Path, out_name: &str) -> eyre::Result<()> {
  44. let mut clang = tokio::process::Command::new("clang++");
  45. clang.arg(path);
  46. clang.arg("-l").arg("dora_node_api_c");
  47. clang.arg("-l").arg("m");
  48. clang.arg("-l").arg("rt");
  49. clang.arg("-l").arg("dl");
  50. clang.arg("-pthread");
  51. clang.arg("-L").arg(root.join("target").join("release"));
  52. clang
  53. .arg("--output")
  54. .arg(Path::new("../build").join(out_name));
  55. if let Some(parent) = path.parent() {
  56. clang.current_dir(parent);
  57. }
  58. if !clang.status().await?.success() {
  59. bail!("failed to compile c++ node");
  60. };
  61. Ok(())
  62. }
  63. async fn build_cxx_operator(path: &Path, out_name: &str) -> eyre::Result<()> {
  64. let object_file_path = Path::new("../build").join(out_name).with_extension("o");
  65. let mut compile = tokio::process::Command::new("clang++");
  66. compile.arg("-c").arg(path);
  67. compile.arg("-o").arg(&object_file_path);
  68. compile.arg("-fPIC");
  69. if let Some(parent) = path.parent() {
  70. compile.current_dir(parent);
  71. }
  72. if !compile.status().await?.success() {
  73. bail!("failed to compile cxx operator");
  74. };
  75. let mut link = tokio::process::Command::new("clang++");
  76. link.arg("-shared").arg(&object_file_path);
  77. link.arg("-o")
  78. .arg(Path::new("../build").join(out_name).with_extension("so"));
  79. if let Some(parent) = path.parent() {
  80. link.current_dir(parent);
  81. }
  82. if !link.status().await?.success() {
  83. bail!("failed to create shared library from cxx operator (c api)");
  84. };
  85. Ok(())
  86. }

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl