diff --git a/examples/c++-dataflow/run.rs b/examples/c++-dataflow/run.rs index fa2338e8..4a852f06 100644 --- a/examples/c++-dataflow/run.rs +++ b/examples/c++-dataflow/run.rs @@ -1,5 +1,9 @@ use eyre::{bail, Context}; -use std::path::Path; +use std::{ + env::consts::{DLL_PREFIX, DLL_SUFFIX}, + ffi::{OsStr, OsString}, + path::Path, +}; #[tokio::main] async fn main() -> eyre::Result<()> { @@ -88,7 +92,7 @@ async fn build_cxx_operator(path: &Path, out_name: &str) -> eyre::Result<()> { let mut link = tokio::process::Command::new("clang++"); link.arg("-shared").arg(&object_file_path); link.arg("-o") - .arg(Path::new("../build").join(format!("lib{out_name}.so"))); + .arg(Path::new("../build").join(library_filename(out_name))); if let Some(parent) = path.parent() { link.current_dir(parent); } @@ -98,3 +102,14 @@ async fn build_cxx_operator(path: &Path, out_name: &str) -> eyre::Result<()> { Ok(()) } + +// taken from `rust_libloading` crate by Simonas Kazlauskas, licensed under the ISC license ( +// see https://github.com/nagisa/rust_libloading/blob/master/LICENSE) +pub fn library_filename>(name: S) -> OsString { + let name = name.as_ref(); + let mut string = OsString::with_capacity(name.len() + DLL_PREFIX.len() + DLL_SUFFIX.len()); + string.push(DLL_PREFIX); + string.push(name); + string.push(DLL_SUFFIX); + string +} diff --git a/examples/c-dataflow/run.rs b/examples/c-dataflow/run.rs index 2b3d4c15..07d934d2 100644 --- a/examples/c-dataflow/run.rs +++ b/examples/c-dataflow/run.rs @@ -1,5 +1,9 @@ use eyre::{bail, Context}; -use std::path::Path; +use std::{ + env::consts::{DLL_PREFIX, DLL_SUFFIX}, + ffi::{OsStr, OsString}, + path::Path, +}; #[tokio::main] async fn main() -> eyre::Result<()> { @@ -79,10 +83,22 @@ async fn build_c_operator(root: &Path) -> eyre::Result<()> { let mut link = tokio::process::Command::new("clang"); link.arg("-shared").arg("build/operator.o"); - link.arg("-o").arg("build/liboperator.so"); + link.arg("-o") + .arg(Path::new("build").join(library_filename("operator"))); if !link.status().await?.success() { bail!("failed to link c operator"); }; Ok(()) } + +// taken from `rust_libloading` crate by Simonas Kazlauskas, licensed under the ISC license ( +// see https://github.com/nagisa/rust_libloading/blob/master/LICENSE) +pub fn library_filename>(name: S) -> OsString { + let name = name.as_ref(); + let mut string = OsString::with_capacity(name.len() + DLL_PREFIX.len() + DLL_SUFFIX.len()); + string.push(DLL_PREFIX); + string.push(name); + string.push(DLL_SUFFIX); + string +}