Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Jun 3, 2024
1 parent 6f7476f commit 1685e60
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 150 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- markdownlint-disable no-inline-html first-line-heading no-emphasis-as-heading -->

<div align="center">

# `xwin`
Expand Down
23 changes: 19 additions & 4 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,22 @@ impl Ctx {

let splat_config = match &ops {
crate::Ops::Splat(config) => {
let splat_roots = crate::splat::prep_splat(self.clone(), &config.output, &crt_version, config.use_winsysroot_style)?;
let splat_roots = crate::splat::prep_splat(
self.clone(),
&config.output,
config.use_winsysroot_style.then_some(&crt_version),
)?;
let mut config = config.clone();
config.output = splat_roots.root.clone();

Some((splat_roots, config))
}
crate::Ops::Minimize(config) => {
let splat_roots = crate::splat::prep_splat(self.clone(), &config.splat_output, &crt_version, config.use_winsysroot_style)?;
let splat_roots = crate::splat::prep_splat(
self.clone(),
&config.splat_output,
config.use_winsysroot_style.then_some(&crt_version),
)?;

let config = crate::SplatConfig {
preserve_ms_arch_notation: config.preserve_ms_arch_notation,
Expand Down Expand Up @@ -268,7 +276,7 @@ impl Ctx {
let sdk_headers = results.into_iter().collect::<Result<Vec<_>, _>>()?;
let sdk_headers = sdk_headers.into_iter().flatten().collect();

let Some(roots) = splat_config.map(|(sr, _)| sr) else {
let Some((roots, sc)) = splat_config else {
return Ok(());
};

Expand All @@ -277,7 +285,14 @@ impl Ctx {
let crt_ft = crt_ft.lock().take();
let atl_ft = atl_ft.lock().take();

crate::splat::finalize_splat(&self, &roots, sdk_headers, crt_ft, atl_ft)?;
crate::splat::finalize_splat(
&self,
sc.use_winsysroot_style.then_some(&sdk_version),
&roots,
sdk_headers,
crt_ft,
atl_ft,
)?;
}

Ok(())
Expand Down
6 changes: 3 additions & 3 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{cmp, collections::BTreeMap};

use crate::Ctx;

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
pub struct Payload {
#[serde(rename = "fileName")]
pub file_name: String,
Expand Down Expand Up @@ -57,13 +57,13 @@ pub enum ItemKind {
Zip,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone, Copy)]
#[serde(rename_all = "camelCase")]
pub struct InstallSizes {
pub target_drive: Option<u64>,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ManifestItem {
pub id: String,
Expand Down
114 changes: 60 additions & 54 deletions src/splat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ pub(crate) struct SplatRoots {
src: PathBuf,
}

pub(crate) fn prep_splat(ctx: std::sync::Arc<Ctx>, root: &Path, crt_version: &String, use_winsysroot_style: bool) -> Result<SplatRoots, Error> {
pub(crate) fn prep_splat(
ctx: std::sync::Arc<Ctx>,
root: &Path,
winroot: Option<&str>,
) -> Result<SplatRoots, Error> {
// Ensure we create the path first, you can't canonicalize a non-existant path
if !root.exists() {
std::fs::create_dir_all(root)
Expand All @@ -61,10 +65,8 @@ pub(crate) fn prep_splat(ctx: std::sync::Arc<Ctx>, root: &Path, crt_version: &St

let root = crate::util::canonicalize(root)?;

let (crt_root, sdk_root) = if use_winsysroot_style {
let mut crt = root.join("VC");
crt.push("Tools");
crt.push("MSVC");
let (crt_root, sdk_root) = if let Some(crt_version) = winroot {
let mut crt = root.join("VC/Tools/MSVC");
crt.push(crt_version);

let mut sdk = root.join("Windows Kits");
Expand Down Expand Up @@ -259,13 +261,13 @@ pub(crate) fn splat(
inc.push(sdk_version);
inc
} else {
let mut target = roots.sdk.join("include");

if config.use_winsysroot_style {
let mut tar = roots.sdk.join("include");
tar.push(sdk_version);
tar
} else {
roots.sdk.join("include")
target.push(sdk_version);
}

target
};

vec![Mapping {
Expand All @@ -279,14 +281,14 @@ pub(crate) fn splat(
}
PayloadKind::SdkLibs => {
src.push("lib/um");
let mut target = if config.use_winsysroot_style {
let mut tar = roots.sdk.join("lib");
tar.push(sdk_version);
tar.push("um");
tar
} else {
roots.sdk.join("lib/um")
};

let mut target = roots.sdk.join("lib");

if config.use_winsysroot_style {
target.push(sdk_version);
}

target.push("um");

push_arch(
&mut src,
Expand All @@ -309,14 +311,14 @@ pub(crate) fn splat(
}
PayloadKind::SdkStoreLibs => {
src.push("lib/um");
let target = if config.use_winsysroot_style {
let mut tar = roots.sdk.join("lib");
tar.push(sdk_version);
tar.push("um");
tar
} else {
roots.sdk.join("lib/um")
};

let mut target = roots.sdk.join("lib");

if config.use_winsysroot_style {
target.push(sdk_version);
}

target.push("um");

Arch::iter(arches)
.map(|arch| -> Result<Mapping<'_>, Error> {
Expand All @@ -342,23 +344,20 @@ pub(crate) fn splat(
let inc_src = src.join("include/ucrt");
let tree = get_tree(&inc_src)?;

let target = if map.is_some() {
let mut inc = roots.sdk.clone();
inc.push("Include");
let mut target = if map.is_some() {
let mut inc = roots.sdk.join("Include");
inc.push(sdk_version);
inc.push("ucrt");
inc
} else {
let mut target = roots.sdk.join("include");
if config.use_winsysroot_style {
let mut tar = roots.sdk.join("include");
tar.push(sdk_version);
tar.push("ucrt");
tar
} else {
roots.sdk.join("include/ucrt")
target.push(sdk_version);
}
target
};

target.push("ucrt");

let mut mappings = vec![Mapping {
src: inc_src,
target,
Expand All @@ -369,14 +368,15 @@ pub(crate) fn splat(
}];

src.push("lib/ucrt");
let target = if config.use_winsysroot_style {
let mut tar = roots.sdk.join("lib");
tar.push(sdk_version);
tar.push("ucrt");
tar
} else {
roots.sdk.join("lib/ucrt")
};

let mut target = roots.sdk.join("lib");

if config.use_winsysroot_style {
target.push(sdk_version);
}

target.push("ucrt");

for arch in Arch::iter(arches) {
let mut src = src.clone();
let mut target = target.clone();
Expand Down Expand Up @@ -714,9 +714,9 @@ pub(crate) fn splat(
})
.collect_into_vec(&mut results);

match kind {
PayloadKind::SdkLibs => {
if !config.use_winsysroot_style {
if !config.use_winsysroot_style {
match kind {
PayloadKind::SdkLibs => {
// Symlink sdk/lib/{sdkversion} -> sdk/lib, regardless of filesystem case sensitivity.
let mut versioned_linkname = roots.sdk.clone();
versioned_linkname.push("lib");
Expand All @@ -737,9 +737,7 @@ pub(crate) fn splat(
}
}
}
}
PayloadKind::SdkHeaders => {
if !config.use_winsysroot_style {
PayloadKind::SdkHeaders => {
// Symlink sdk/include/{sdkversion} -> sdk/include, regardless of filesystem case sensitivity.
let mut versioned_linkname = roots.sdk.clone();
versioned_linkname.push("include");
Expand All @@ -760,9 +758,9 @@ pub(crate) fn splat(
}
}
}
}
_ => (),
};
_ => (),
};
}
}

item.progress.finish_with_message("📦 splatted");
Expand All @@ -774,6 +772,7 @@ pub(crate) fn splat(

pub(crate) fn finalize_splat(
ctx: &Ctx,
sdk_version: Option<&str>,
roots: &SplatRoots,
sdk_headers: Vec<SdkHeaders>,
crt_headers: Option<crate::unpack::FileTree>,
Expand Down Expand Up @@ -972,7 +971,14 @@ pub(crate) fn finalize_splat(

// There is a um/gl directory, but of course there is an include for GL/
// instead, so fix that as well :p
symlink("gl", &roots.sdk.join("include/um/GL"))?;
if let Some(_sdk_version) = sdk_version {
// let mut target = roots.sdk.join("Include");
// target.push(sdk_version);
// target.push("um/GL");
// symlink("gl", &target)?;
} else {
symlink("gl", &roots.sdk.join("include/um/GL"))?;
}

Ok(())
}
Expand Down
Loading

0 comments on commit 1685e60

Please sign in to comment.