Skip to content
Open
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
15 changes: 15 additions & 0 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,21 +277,35 @@ impl Ctx {

let mut splat_config = match &ops {
crate::Ops::Splat(config) => {
if config.preserve_versions && !config.use_winsysroot_style {
anyhow::bail!("preserve_versions requires use_winsysroot_style");
}

let splat_roots = crate::splat::prep_splat(
self.clone(),
&config.output,
config.use_winsysroot_style.then_some(&crt_version),
Some(&sdk_version),
vcrd_version.as_deref(),
config.preserve_versions,
)?;
let mut config = config.clone();
config.output = splat_roots.root.clone();

Some((splat_roots, config))
}
crate::Ops::Minimize(config) => {
if config.preserve_versions && !config.use_winsysroot_style {
anyhow::bail!("preserve_versions requires use_winsysroot_style");
}

let splat_roots = crate::splat::prep_splat(
self.clone(),
&config.splat_output,
config.use_winsysroot_style.then_some(&crt_version),
Some(&sdk_version),
vcrd_version.as_deref(),
config.preserve_versions,
)?;

let config = crate::SplatConfig {
Expand All @@ -300,6 +314,7 @@ impl Ctx {
include_debug_symbols: config.include_debug_symbols,
enable_symlinks: config.enable_symlinks,
use_winsysroot_style: config.use_winsysroot_style,
preserve_versions: config.preserve_versions,
output: splat_roots.root.clone(),
map: Some(config.map.clone()),
copy: config.copy,
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ pub struct SplatOptions {
/// and --disable-symlinks for use with clang-cl on Windows.
#[arg(long)]
use_winsysroot_style: bool,
/// Keep other CRT/SDK/VCR versions already present in the splat output;
/// only the version being installed is removed first
/// (requires --use-winsysroot-style)
#[arg(long, requires = "use_winsysroot_style")]
preserve_versions: bool,
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -354,6 +359,7 @@ fn main() -> Result<(), Error> {
enable_symlinks: !options.disable_symlinks,
preserve_ms_arch_notation: options.preserve_ms_arch_notation,
use_winsysroot_style: options.use_winsysroot_style,
preserve_versions: options.preserve_versions,
copy,
map,
output: output.unwrap_or_else(|| ctx.work_dir.join("splat")),
Expand All @@ -373,6 +379,7 @@ fn main() -> Result<(), Error> {
enable_symlinks: !options.disable_symlinks,
preserve_ms_arch_notation: options.preserve_ms_arch_notation,
use_winsysroot_style: options.use_winsysroot_style,
preserve_versions: options.preserve_versions,
splat_output: output.unwrap_or_else(|| ctx.work_dir.join("splat")),
copy,
minimize_output,
Expand Down
1 change: 1 addition & 0 deletions src/minimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct MinimizeConfig {
pub include_debug_symbols: bool,
pub enable_symlinks: bool,
pub use_winsysroot_style: bool,
pub preserve_versions: bool,
pub preserve_ms_arch_notation: bool,
pub splat_output: PathBuf,
pub copy: bool,
Expand Down
44 changes: 37 additions & 7 deletions src/splat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub struct SplatConfig {
pub enable_symlinks: bool,
pub preserve_ms_arch_notation: bool,
pub use_winsysroot_style: bool,
pub preserve_versions: bool,
pub output: PathBuf,
pub map: Option<PathBuf>,
pub copy: bool,
Expand Down Expand Up @@ -79,6 +80,9 @@ pub(crate) fn prep_splat(
ctx: std::sync::Arc<Ctx>,
root: &Path,
winroot: Option<&str>,
sdk_version: Option<&str>,
vcrd_version: Option<&str>,
preserve_versions: bool,
) -> Result<SplatRoots, Error> {
// Ensure we create the path first, you can't canonicalize a non-existant path
if !root.exists() {
Expand Down Expand Up @@ -107,14 +111,40 @@ pub(crate) fn prep_splat(
.with_context(|| format!("unable to delete existing CRT directory {crt_root}"))?;
}

if sdk_root.exists() {
std::fs::remove_dir_all(&sdk_root)
.with_context(|| format!("unable to delete existing SDK directory {sdk_root}"))?;
}
// In winsysroot style, the CRT root is already version scoped, but the SDK
// and VCR roots contain every version that has ever been splatted, so when
// the user wants to preserve previously installed versions we only remove
// the directories belonging to the version being (re)installed
if preserve_versions && winroot.is_some() {
if let Some(sdk_version) = sdk_version {
for subdir in ["Include", "Lib"] {
let versioned = sdk_root.join(subdir).join(sdk_version);
if versioned.exists() {
std::fs::remove_dir_all(&versioned).with_context(|| {
format!("unable to delete existing SDK {subdir} directory {versioned}")
})?;
}
}
}

if let Some(vcrd_version) = vcrd_version {
let versioned = vcrd_root.join(vcrd_version);
if versioned.exists() {
std::fs::remove_dir_all(&versioned).with_context(|| {
format!("unable to delete existing VCR directory {versioned}")
})?;
}
}
} else {
if sdk_root.exists() {
std::fs::remove_dir_all(&sdk_root)
.with_context(|| format!("unable to delete existing SDK directory {sdk_root}"))?;
}

if vcrd_root.exists() {
std::fs::remove_dir_all(&vcrd_root)
.with_context(|| format!("unable to delete existing VCR directory {vcrd_root}"))?;
if vcrd_root.exists() {
std::fs::remove_dir_all(&vcrd_root)
.with_context(|| format!("unable to delete existing VCR directory {vcrd_root}"))?;
}
}

std::fs::create_dir_all(&crt_root)
Expand Down
3 changes: 3 additions & 0 deletions tests/compiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ fn verify_compiles() {
enable_symlinks: matches!(style, Style::Default),
preserve_ms_arch_notation: matches!(style, Style::WinSysRoot),
use_winsysroot_style: matches!(style, Style::WinSysRoot),
preserve_versions: false,
map: None,
copy: true,
output: output_dir.clone(),
Expand Down Expand Up @@ -218,6 +219,7 @@ fn verify_compiles_minimized() {
enable_symlinks: true,
preserve_ms_arch_notation: false,
use_winsysroot_style: false,
preserve_versions: false,
map: map_path.clone(),
copy: true,
splat_output: output_dir.clone(),
Expand Down Expand Up @@ -336,6 +338,7 @@ fn verify_aarch64_compiles() {
enable_symlinks: matches!(style, Style::Default),
preserve_ms_arch_notation: matches!(style, Style::WinSysRoot),
use_winsysroot_style: matches!(style, Style::WinSysRoot),
preserve_versions: false,
map: None,
copy: true,
output: output_dir.clone(),
Expand Down
1 change: 1 addition & 0 deletions tests/deterministic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn verify_deterministic() {
enable_symlinks: true,
preserve_ms_arch_notation: false,
use_winsysroot_style: false,
preserve_versions: false,
map: None,
copy: true,
output: output_dir.clone(),
Expand Down
5 changes: 5 additions & 0 deletions tests/snapshots/xwin-minimize.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Options:
--preserve-ms-arch-notation and --disable-symlinks for use with
clang-cl on Windows

--preserve-versions
Keep other CRT/SDK/VCR versions already present in the splat output;
only the version being installed is removed first (requires
--use-winsysroot-style)

--map <MAP>
The path of the filter file that is generated. Defaults to
./.xwin-cache/xwin-map.toml
Expand Down
5 changes: 5 additions & 0 deletions tests/snapshots/xwin-splat.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Options:
--preserve-ms-arch-notation and --disable-symlinks for use with
clang-cl on Windows

--preserve-versions
Keep other CRT/SDK/VCR versions already present in the splat output;
only the version being installed is removed first (requires
--use-winsysroot-style)

--output <OUTPUT>
The root output directory. Defaults to `./.xwin-cache/splat` if not
specified
Expand Down