Skip to content

Commit

Permalink
Try to use the "cargo metadata" command when automatically discoverin…
Browse files Browse the repository at this point in the history
…g the target dir
  • Loading branch information
Michael-F-Bryan authored and hannobraun committed Jul 18, 2022
1 parent 4a80380 commit 2df4c33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fj-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ categories = ["encoding", "mathematics", "rendering"]
libloading = "0.7.2"
notify = "5.0.0-pre.15"
thiserror = "1.0.31"
cargo_metadata = "0.15.0"

[dependencies.fj]
version = "0.8.0"
Expand Down
18 changes: 16 additions & 2 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
io,
path::PathBuf,
path::{Path, PathBuf},
process::Command,
sync::mpsc,
thread,
};

use cargo_metadata::Metadata;
use notify::Watcher as _;
use thiserror::Error;

Expand Down Expand Up @@ -64,7 +65,9 @@ impl Model {

let lib_path = {
let file = HostPlatform::lib_file_name(&name);
let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
let target_dir = target_dir
.or_else(|| cargo_metadata_target_dir(&path))
.unwrap_or_else(|| path.join("target"));
target_dir.join("debug").join(file)
};

Expand Down Expand Up @@ -285,3 +288,14 @@ pub enum Error {
}

type ModelFn = unsafe extern "C" fn(args: &Parameters) -> fj::Shape;

fn cargo_metadata_target_dir(model: &Path) -> Option<PathBuf> {
let Metadata {
target_directory, ..
} = cargo_metadata::MetadataCommand::new()
.current_dir(model)
.exec()
.ok()?;

Some(target_directory.into())
}

0 comments on commit 2df4c33

Please sign in to comment.