Skip to content

Commit

Permalink
Python fixes on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
tychedelia committed Nov 3, 2023
1 parent b429c88 commit fe7a1ba
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions td-rs-xtask/msvc/chop/RustCHOP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
Expand All @@ -81,7 +81,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSCHOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
4 changes: 2 additions & 2 deletions td-rs-xtask/msvc/dat/RustDAT.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
Expand All @@ -81,7 +81,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSDATEXAMPLE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
4 changes: 2 additions & 2 deletions td-rs-xtask/msvc/sop/RustSOP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
Expand All @@ -81,7 +81,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSSOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
4 changes: 2 additions & 2 deletions td-rs-xtask/msvc/top/RustTOP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>
Expand All @@ -81,7 +81,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;CPLUSPLUSTOPEXAMPLE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;$(PreprocessorDefinitions);%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
11 changes: 2 additions & 9 deletions td-rs-xtask/src/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fs::metadata;
use crate::config::Config;
use crate::metadata::PluginType;
use crate::{build, PLUGIN_HOME};
Expand Down Expand Up @@ -43,7 +44,7 @@ pub(crate) fn build_plugin(
&["--release", &format!("--target={target}")],
)?;

let is_python_enabled = is_python_enabled(plugin, &plugin_type);
let is_python_enabled = crate::metadata::is_python_enabled(plugin, &plugin_type);
let plugin = &plugin.replace('-', "_");
let path = pbxproj_path(plugin);

Expand All @@ -56,14 +57,6 @@ pub(crate) fn build_plugin(
Ok(())
}

fn is_python_enabled(plugin: &str, plugin_type: &PluginType) -> bool {
let pkg = crate::metadata::fetch_cargo_workspace_package(plugin).unwrap();
let parent_dep = pkg.dependencies.iter()
.find(|dep| dep.name == plugin_type.to_plugin_name())
.expect("Could not find plugin dependency");
parent_dep.features.iter().find(|feature| feature == &"python").is_some()
}

fn move_plugin(plugin: &str, path: &PathBuf) -> anyhow::Result<()> {
fs_extra::dir::remove(path.parent().unwrap())
.context("Could not remove xcode project directory")?;
Expand Down
8 changes: 8 additions & 0 deletions td-rs-xtask/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,11 @@ pub(crate) fn list_plugins() -> anyhow::Result<Vec<String>> {
.collect::<Vec<String>>();
Ok(ws_members)
}

pub fn is_python_enabled(plugin: &str, plugin_type: &PluginType) -> bool {
let pkg = crate::metadata::fetch_cargo_workspace_package(plugin).unwrap();
let parent_dep = pkg.dependencies.iter()
.find(|dep| dep.name == plugin_type.to_plugin_name())
.expect("Could not find plugin dependency");
parent_dep.features.iter().find(|feature| feature == &"python").is_some()
}
6 changes: 4 additions & 2 deletions td-rs-xtask/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub(crate) fn build_plugin(

println!("Run msbuild");
fs_extra::copy_items(&to_copy, ".", &CopyOptions::new().overwrite(true))?;
run_msbuild(config, &target, &plugin)?;
let is_python_enabled = crate::metadata::is_python_enabled(plugin, &plugin_type);
run_msbuild(config, &target, &plugin, is_python_enabled)?;
fs_extra::remove_items(&files)?;

println!("Move plugin to target");
Expand Down Expand Up @@ -85,7 +86,7 @@ fn plugin_target_path(plugin: &str) -> PathBuf {
plugin_target_path
}

fn run_msbuild(config: &Config, target: &str, plugin: &str) -> anyhow::Result<()> {
fn run_msbuild(config: &Config, target: &str, plugin: &str, is_python_enabled: bool) -> anyhow::Result<()> {
let msbuild = find_msbuild()?;
let msbuild = msbuild.to_str().expect("Could not find msbuild");
let lib = format!("{}.lib", plugin.replace("-", "_"));
Expand All @@ -94,6 +95,7 @@ fn run_msbuild(config: &Config, target: &str, plugin: &str) -> anyhow::Result<()
let mut cmd = Command::new(msbuild)
.arg(format!("/p:AdditionalIncludeDirectories={py_include}"))
.arg(format!("/p:AdditionalLibraryDirectories={py_lib}"))
.arg(if is_python_enabled {"/p:PreprocessorDefinitions=PYTHON_ENABLED"} else {""})
.arg("/p:Configuration=Release")
.arg("/t:Rebuild")
.arg("/p:Platform=x64")
Expand Down

0 comments on commit fe7a1ba

Please sign in to comment.