Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
jroesch committed Apr 6, 2021
1 parent b6ed311 commit faa290a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
30 changes: 22 additions & 8 deletions rust/tvm-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern crate bindgen;
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use tvm_build::{BuildConfig};
use tvm_build::BuildConfig;

/// The necessary information for detecting a TVM installation.
struct TVMInstall {
Expand All @@ -41,9 +41,13 @@ fn find_using_tvm_path<P: AsRef<Path>>(tvm_path: P) -> Result<TVMInstall> {
fn if_unset<K: AsRef<std::ffi::OsStr>, V: AsRef<std::ffi::OsStr>>(k: K, v: V) -> Result<()> {
match std::env::var(k.as_ref()) {
Ok(other) if other != "" => {
println!("cargo:warning=Using existing environment variable setting {:?}={:?}", k.as_ref(), v.as_ref());
println!(
"cargo:warning=Using existing environment variable setting {:?}={:?}",
k.as_ref(),
v.as_ref()
);
}
_ => std::env::set_var(k, v)
_ => std::env::set_var(k, v),
}

Ok(())
Expand All @@ -70,7 +74,10 @@ fn find_using_tvm_build() -> Result<TVMInstall> {
}

fn main() -> Result<()> {
let TVMInstall { source_path, build_path } = match option_env!("TVM_HOME") {
let TVMInstall {
source_path,
build_path,
} = match option_env!("TVM_HOME") {
Some(tvm_path) if tvm_path != "" => find_using_tvm_path(tvm_path),
_ => find_using_tvm_build(),
}?;
Expand All @@ -80,13 +87,18 @@ fn main() -> Result<()> {
if cfg!(feature = "static-linking") {
println!("cargo:rustc-link-lib=static=tvm");
// TODO move this to tvm-build as library_path?
println!("cargo:rustc-link-search=native={}/build", build_path.display());

println!(
"cargo:rustc-link-search=native={}/build",
build_path.display()
);
}

if cfg!(feature = "dynamic-linking") {
println!("cargo:rustc-link-lib=dylib=tvm");
println!("cargo:rustc-link-search=native={}/build", build_path.display());
println!(
"cargo:rustc-link-search=native={}/build",
build_path.display()
);
}

let runtime_api = source_path.join("include/tvm/runtime/c_runtime_api.h");
Expand All @@ -109,7 +121,9 @@ fn main() -> Result<()> {
.derive_eq(true)
.derive_default(true)
.generate()
.map_err(|()| anyhow::anyhow!("bindgen failed to generate the Rust bindings for the C API"))?
.map_err(|()| {
anyhow::anyhow!("bindgen failed to generate the Rust bindings for the C API")
})?
.write_to_file(out_file)
.context("failed to write the generated Rust binding to disk")?;

Expand Down
4 changes: 1 addition & 3 deletions rust/tvm-sys/src/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ pub struct ByteArray {
impl ByteArray {
/// Gets the underlying byte-array
pub fn data(&self) -> &'static [u8] {
unsafe { std::slice::from_raw_parts(
self.array.data as *const u8,
self.array.size as _) }
unsafe { std::slice::from_raw_parts(self.array.data as *const u8, self.array.size as _) }
}

/// Gets the length of the underlying byte-array
Expand Down

0 comments on commit faa290a

Please sign in to comment.