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

feat(bundler): add visual c++ redistributable files with MSM #1368

Merged
merged 2 commits into from
Mar 23, 2021
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
5 changes: 5 additions & 0 deletions .changes/vc-redistributable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-bundler": patch
---

Bundle Visual C++ redistributable files with VC142_CRT merge modules.
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions cli/core/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ impl Build {

if config_.tauri.bundle.active {
let bundler_settings = rust::get_bundler_settings(&config_, self.debug)?;
// move merge modules to the out dir so the bundler can load it
#[cfg(windows)]
{
let (filename, vcruntime_msm) = if cfg!(target_arch = "x86") {
let _ =
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x64.msm"));
(
"Microsoft_VC142_CRT_x86.msm",
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x86.msm").to_vec(),
)
} else {
let _ =
std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x86.msm"));
(
"Microsoft_VC142_CRT_x64.msm",
include_bytes!("./MergeModules/Microsoft_VC142_CRT_x64.msm").to_vec(),
)
};
std::fs::write(bundler_settings.out_dir.join(filename), vcruntime_msm)?;
}
let mut settings_builder = SettingsBuilder::new()
.package_settings(bundler_settings.package_settings)
.bundle_settings(bundler_settings.bundle_settings)
Expand Down
10 changes: 10 additions & 0 deletions cli/tauri-bundler/src/bundle/templates/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
</Component>
</DirectoryRef>

{{#each merge_modules as |msm| ~}}
<DirectoryRef Id="TARGETDIR">
<Merge Id="{{ msm.name }}" SourceFile="{{ msm.path }}" DiskId="1" Language="0"/>
</DirectoryRef>

<Feature Id="{{ msm.name }}" Title="{{ msm.name }}" AllowAdvertise="no" Display="hidden" Level="1">
<MergeRef Id="{{ msm.name }}"/>
</Feature>
{{/each~}}

<Feature
Id="MainProgram"
Title="Application"
Expand Down
35 changes: 35 additions & 0 deletions cli/tauri-bundler/src/bundle/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ pub fn build_wix_app_installer(
data.insert("resources", to_json(resources_wix_string));
data.insert("resource_file_ids", to_json(files_ids));

let merge_modules = get_merge_modules(&settings)?;
data.insert("merge_modules", to_json(merge_modules));

let main_binary = settings
.binaries()
.iter()
Expand Down Expand Up @@ -572,6 +575,38 @@ fn generate_binaries_data(settings: &Settings) -> crate::Result<Vec<Binary>> {
Ok(binaries)
}

#[derive(Serialize)]
struct MergeModule {
name: String,
path: String,
}

fn get_merge_modules(settings: &Settings) -> crate::Result<Vec<MergeModule>> {
let mut merge_modules = Vec::new();
let regex = Regex::new(r"[^\w\d\.]")?;
for msm in glob::glob(
settings
.project_out_directory()
.join("*.msm")
.to_string_lossy()
.to_string()
.as_str(),
)? {
let path = msm?;
let filename = path
.file_name()
.expect("failed to extract merge module filename")
.to_os_string()
.into_string()
.expect("failed to convert merge module filename to string");
merge_modules.push(MergeModule {
name: regex.replace_all(&filename, "").to_string(),
path: path.to_string_lossy().to_string(),
});
}
Ok(merge_modules)
}

/// Generates the data required for the resource bundling on wix
fn generate_resource_data(settings: &Settings) -> crate::Result<ResourceMap> {
let mut resources = ResourceMap::new();
Expand Down