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

Rework PR #123

Merged
merged 4 commits into from
Jun 3, 2024
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
3 changes: 3 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 Expand Up @@ -77,6 +79,7 @@ Fixes the packages to prune unneeded files and adds symlinks to address file cas
* `--include-debug-libs` - The MSVCRT includes (non-redistributable) debug versions of the various libs that are generally uninteresting to keep for most usage
* `--include-debug-symbols` - The MSVCRT includes PDB (debug symbols) files for several of the libraries that are generally uninteresting to keep for most usage
* `--preserve-ms-arch-notation` - By default, we convert the MS specific `x64`, `arm`, and `arm64` target architectures to the more canonical `x86_64`, `aarch`, and `aarch64` of LLVM etc when creating directories/names. Passing this flag will preserve the MS names for those targets
* `--use-winsysroot-style` - Use the /winsysroot layout, so that clang-cl's /winsysroot flag can be used with the output, rather than needing both -vctoolsdir and -winsdkdir. You will likely also want to use --preserve-ms-arch-notation and --disable-symlinks for use with clang-cl on Windows.
* `--output` - The root output directory. Defaults to `./.xwin-cache/splat` if not specified
* `--map` - An optional [map](#map-file) file used to configure what files are splatted, and any additional symlinks to create.

Expand Down
26 changes: 22 additions & 4 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ impl Ctx {
Ok(body)
}

#[allow(clippy::too_many_arguments)]
pub fn execute(
self: std::sync::Arc<Self>,
packages: std::collections::BTreeMap<String, crate::manifest::ManifestItem>,
payloads: Vec<WorkItem>,
crt_version: String,
sdk_version: String,
arches: u32,
variants: u32,
Expand All @@ -179,20 +181,29 @@ impl Ctx {

let splat_config = match &ops {
crate::Ops::Splat(config) => {
let splat_roots = crate::splat::prep_splat(self.clone(), &config.output)?;
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)?;
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,
include_debug_libs: config.include_debug_libs,
include_debug_symbols: config.include_debug_symbols,
enable_symlinks: config.enable_symlinks,
use_winsysroot_style: config.use_winsysroot_style,
output: splat_roots.root.clone(),
map: Some(config.map.clone()),
copy: config.copy,
Expand Down Expand Up @@ -266,7 +277,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 @@ -275,7 +286,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
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pub enum PayloadKind {
}

pub struct PrunedPackageList {
pub crt_version: String,
pub sdk_version: String,
pub payloads: Vec<Payload>,
}
Expand All @@ -204,7 +205,7 @@ pub fn prune_pkg_list(
let pkgs = &pkg_manifest.packages;
let mut payloads = Vec::new();

get_crt(
let crt_version = get_crt(
pkgs,
arches,
variants,
Expand All @@ -215,6 +216,7 @@ pub fn prune_pkg_list(
let sdk_version = get_sdk(pkgs, arches, sdk_version, &mut payloads)?;

Ok(PrunedPackageList {
crt_version,
sdk_version,
payloads,
})
Expand All @@ -227,7 +229,7 @@ fn get_crt(
pruned: &mut Vec<Payload>,
include_atl: bool,
crt_version: Option<String>,
) -> Result<(), Error> {
) -> Result<String, Error> {
fn to_payload(mi: &manifest::ManifestItem, payload: &manifest::Payload) -> Payload {
// These are really the only two we care about
let kind = if mi.id.contains("Headers") {
Expand Down Expand Up @@ -375,7 +377,7 @@ fn get_crt(
}
}

Ok(())
Ok(crt_version)
}

fn get_atl(
Expand Down
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ pub struct SplatOptions {
/// Passing this flag will preserve the MS names for those targets.
#[arg(long)]
preserve_ms_arch_notation: bool,
/// Use the /winsysroot layout, so that clang-cl's /winsysroot flag can be
/// used with the output, rather than needing both -vctoolsdir and
/// -winsdkdir. You will likely also want to use --preserve-ms-arch-notation
/// and --disable-symlinks for use with clang-cl on Windows.
#[arg(long)]
use_winsysroot_style: bool,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -331,6 +337,7 @@ fn main() -> Result<(), Error> {
include_debug_symbols: options.include_debug_symbols,
enable_symlinks: !options.disable_symlinks,
preserve_ms_arch_notation: options.preserve_ms_arch_notation,
use_winsysroot_style: options.use_winsysroot_style,
copy,
map,
output: output.unwrap_or_else(|| ctx.work_dir.join("splat")),
Expand All @@ -349,6 +356,7 @@ fn main() -> Result<(), Error> {
include_debug_symbols: options.include_debug_symbols,
enable_symlinks: !options.disable_symlinks,
preserve_ms_arch_notation: options.preserve_ms_arch_notation,
use_winsysroot_style: options.use_winsysroot_style,
splat_output: output.unwrap_or_else(|| ctx.work_dir.join("splat")),
copy,
minimize_output,
Expand Down Expand Up @@ -419,7 +427,15 @@ fn main() -> Result<(), Error> {
mp.set_move_cursor(true);

let res = std::thread::spawn(move || {
ctx.execute(pkgs, work_items, pruned.sdk_version, arches, variants, op)
ctx.execute(
pkgs,
work_items,
pruned.crt_version,
pruned.sdk_version,
arches,
variants,
op,
)
})
.join();

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
1 change: 1 addition & 0 deletions src/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub struct MinimizeConfig {
pub include_debug_libs: bool,
pub include_debug_symbols: bool,
pub enable_symlinks: bool,
pub use_winsysroot_style: bool,
pub preserve_ms_arch_notation: bool,
pub splat_output: PathBuf,
pub copy: bool,
Expand Down
Loading
Loading