Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added platform trait and specific platforms implementations plust Hos… #383

Merged
merged 1 commit into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#![deny(missing_docs)]

mod platform;

use std::{
collections::{HashMap, HashSet},
ffi::OsStr,
Expand All @@ -18,6 +20,8 @@ use std::{
use notify::Watcher as _;
use thiserror::Error;

use self::platform::HostPlatform;

/// Represents a Fornjot model
pub struct Model {
src_path: PathBuf,
Expand Down Expand Up @@ -47,15 +51,7 @@ impl Model {
let src_path = path.join("src");

let lib_path = {
let file = if cfg!(windows) {
format!("{}.dll", name)
} else if cfg!(target_os = "macos") {
format!("lib{}.dylib", name)
} else {
//Unix
format!("lib{}.so", name)
};

let file = HostPlatform::host_file_name(&name);
let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
target_dir.join("debug").join(file)
};
Expand Down
45 changes: 45 additions & 0 deletions fj-host/src/platform.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Represents platform trait
trait Platform {
fn file_name(name: &str) -> String;
ozghimire marked this conversation as resolved.
Show resolved Hide resolved
}

// 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)
}
}
}
ozghimire marked this conversation as resolved.
Show resolved Hide resolved