Skip to content

Commit

Permalink
Move macos build to single file.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Nov 29, 2023
1 parent f03be96 commit b8f35f1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 2,031 deletions.
5 changes: 1 addition & 4 deletions td-rs-xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
toml = "0.8"
cargo_metadata = "0.15.4"
homedir = "0.2"

[target.'cfg(target_os = "macos")'.dependencies]
plist = "1"
homedir = "0.2"
117 changes: 83 additions & 34 deletions td-rs-xtask/src/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use crate::metadata::PluginType;
use crate::{build, PLUGIN_HOME};
use anyhow::Context;
use fs_extra::dir::CopyOptions;
use plist::Value;
use std::fs::metadata;
use std::path::{Path, PathBuf};
use std::process::Command;

Expand Down Expand Up @@ -53,7 +51,7 @@ pub(crate) fn build_plugin(
println!("Building xcode project");
build_xcode(config, plugin, is_python_enabled)?;
println!("Moving plugin to {:?}", PLUGIN_HOME);
move_plugin(plugin, &path)?;
// move_plugin(plugin, &path)?;
Ok(())
}

Expand Down Expand Up @@ -112,38 +110,89 @@ fn write_xcodeproj(
const BUNDLE_KEY: &str = "E23329D61DF092AD0002B4FE";
const BUNDLE_CONFIGURATION_KEY: &str = "E23329D51DF092AD0002B4FE";

let plugin_type_name = plugin_type.to_short_name();

std::fs::create_dir_all(path.parent().unwrap())
.context("Could not create xcode project directory")?;
let mut project = Value::from_file(format!(
"td-rs-xtask/xcode/{plugin_type_name}/project.pbxproj"
))
.expect("Could not read xcode project");
let p = project.as_dictionary_mut().unwrap();
let objs = p.get_mut("objects").unwrap().as_dictionary_mut().unwrap();
let lib = objs.get_mut(LIB_KEY).unwrap().as_dictionary_mut().unwrap();
lib.insert("name".to_string(), Value::String(format!("lib{plugin}.a")));
lib.insert(
"path".to_string(),
Value::String(format!("target/{target}/release/lib{plugin}.a")),
);
let bundle = objs
.get_mut(BUNDLE_KEY)
.unwrap()
.as_dictionary_mut()
.unwrap();
bundle.insert(
"name".to_string(),
Value::String(format!("{plugin}.plugin")),
);
let bundle_config = objs
.get_mut(BUNDLE_CONFIGURATION_KEY)
.unwrap()
.as_dictionary_mut()
.unwrap();
bundle_config.insert("name".to_string(), Value::String(plugin.to_string()));
bundle_config.insert("productName".to_string(), Value::String(plugin.to_string()));
project.to_file_xml(path)?;
let project = std::fs::read_to_string("td-rs-xtask/xcode/project.pbxproj")
.expect("Could not read xcode project")
.replace("{{ LIB_NAME }}", &format!("lib{plugin}.a"))
.replace(
"{{ LIB_PATH }}",
&format!("target/{}/release/lib{plugin}.a", target),
)
.replace("{{ PLUGIN_FILE_NAME }}", &format!("{plugin}.plugin"))
.replace("{{ PLUGIN_NAME }}", &plugin)
.replace("{{ PLUGIN_PRODUCT_NAME }}", &plugin)
.replace(
"{{ TD_OP_H_PATH }}",
&format!(
"{}/src/{}_CPlusPlusBase.h",
plugin_type.to_plugin_name(),
plugin_type.to_short_name().to_uppercase()
),
)
.replace(
"{{ TD_OP_H_NAME }}",
&format!(
"{}_CPlusPlusBase.h",
plugin_type.to_short_name().to_uppercase()
),
)
.replace(
"{{ PLUGIN_CPP_NAME }}",
&format!(
"Rust{}Plugin.cpp",
plugin_type.to_short_name().to_title_case()
),
)
.replace(
"{{ PLUGIN_CPP_PATH }}",
&format!(
"{}/src/Rust{}Plugin.cpp",
plugin_type.to_plugin_name(),
plugin_type.to_short_name().to_title_case()
),
)
.replace(
"{{ PLUGIN_H_NAME }}",
&format!(
"Rust{}Plugin.h",
plugin_type.to_short_name().to_title_case()
),
)
.replace(
"{{ PLUGIN_H_PATH }}",
&format!(
"{}/src/Rust{}Plugin.h",
plugin_type.to_plugin_name(),
plugin_type.to_short_name().to_title_case()
),
)
.replace(
"{{ OP_LIB_NAME }}",
&format!("lib{}.a", plugin_type.to_plugin_name().replace("-", "_")),
)
.replace(
"{{ OP_LIB_PATH }}",
&format!(
"target/{}/release/lib{}.a",
target,
plugin_type.to_plugin_name().replace("-", "_")
),
);
std::fs::write(path, project)?;
Ok(())
}

trait ToTitleCase {
fn to_title_case(&self) -> String;
}

impl ToTitleCase for str {
fn to_title_case(&self) -> String {
let mut c = self.chars();
match c.next() {
None => String::new(),
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
}
}
}
Loading

0 comments on commit b8f35f1

Please sign in to comment.