Browse Source

Update example run scripts to use platform-dependent shared library name

tags/v0.0.0-test.4
Philipp Oppermann 3 years ago
parent
commit
9ff649e43a
Failed to extract signature
2 changed files with 35 additions and 4 deletions
  1. +17
    -2
      examples/c++-dataflow/run.rs
  2. +18
    -2
      examples/c-dataflow/run.rs

+ 17
- 2
examples/c++-dataflow/run.rs View File

@@ -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<S: AsRef<OsStr>>(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
}

+ 18
- 2
examples/c-dataflow/run.rs View File

@@ -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<S: AsRef<OsStr>>(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
}

Loading…
Cancel
Save