mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-25 16:45:52 +00:00
Merge pull request #383 from ozghimire/platform-api
Added platform trait and specific platforms implementations plust Hos…
This commit is contained in:
commit
3f65f501be
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
mod platform;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
@ -18,6 +20,8 @@ use std::{
|
|||||||
use notify::Watcher as _;
|
use notify::Watcher as _;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use self::platform::HostPlatform;
|
||||||
|
|
||||||
/// Represents a Fornjot model
|
/// Represents a Fornjot model
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
src_path: PathBuf,
|
src_path: PathBuf,
|
||||||
@ -47,15 +51,7 @@ impl Model {
|
|||||||
let src_path = path.join("src");
|
let src_path = path.join("src");
|
||||||
|
|
||||||
let lib_path = {
|
let lib_path = {
|
||||||
let file = if cfg!(windows) {
|
let file = HostPlatform::host_file_name(&name);
|
||||||
format!("{}.dll", name)
|
|
||||||
} else if cfg!(target_os = "macos") {
|
|
||||||
format!("lib{}.dylib", name)
|
|
||||||
} else {
|
|
||||||
//Unix
|
|
||||||
format!("lib{}.so", name)
|
|
||||||
};
|
|
||||||
|
|
||||||
let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
|
let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
|
||||||
target_dir.join("debug").join(file)
|
target_dir.join("debug").join(file)
|
||||||
};
|
};
|
||||||
|
45
fj-host/src/platform.rs
Normal file
45
fj-host/src/platform.rs
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Represents platform trait
|
||||||
|
trait Platform {
|
||||||
|
fn file_name(name: &str) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Represents all platforms supported
|
||||||
|
|
||||||
|
// Mac OS
|
||||||
|
struct Macos;
|
||||||
|
// Windows
|
||||||
|
struct Windows;
|
||||||
|
// Linux
|
||||||
|
struct Unix;
|
||||||
|
|
||||||
|
impl Platform for Windows {
|
||||||
|
fn file_name(name: &str) -> String {
|
||||||
|
format!("{}.dll", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Platform for Macos {
|
||||||
|
fn file_name(name: &str) -> String {
|
||||||
|
format!("lib{}.dylib", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Platform for Unix {
|
||||||
|
fn file_name(name: &str) -> String {
|
||||||
|
format!("lib{}.so", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Represents common apis availiable independent of hosts
|
||||||
|
pub struct HostPlatform;
|
||||||
|
|
||||||
|
impl HostPlatform {
|
||||||
|
pub fn host_file_name(name: &str) -> String {
|
||||||
|
if cfg!(windows) {
|
||||||
|
Windows::file_name(name)
|
||||||
|
} else if cfg!(target_os = "macos") {
|
||||||
|
Macos::file_name(name)
|
||||||
|
} else {
|
||||||
|
//Unix
|
||||||
|
Unix::file_name(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user