Move asset hashing into the CLI (#3988)
* Fix deduping assets * hash assets in the linker * fix extracting assets * Fix the hashed asset name * deserialize the asset back from the link section * prevent the read from being inlined * remove some extra logs * Fix liveview routing * Only look for direct dependencies on dioxus features * fix wasm split test * On wasm, create a new object file with the asset information * Fix multiple assets * add a regression test for 3467 * fix image link * fix linker out file * fix linux linker args * add windows linker command * fix linux link args * fix windows target triple * Expose an option to build assets in the linker intercept * Fix the standalone optimizer and document it in the dx help command * include the cli opt version in the hash * fix clippy * fix ssg port * add a safety note to the read_volatile call * move found assets log * fix some merge conflicts * fix build * make most env var for the linker optional * guess the target triple when dx acts as the linker intercept * automatically find the linker for normal builds * use the right linker in wasm mode * fix mac linker * look inside archive files (rlibs) * remove out.txt * fix clippy * fix typo * fix clippy * fix build * fix dx link name in docs * ignore libcompiler_builtins warnings * fix playwright * pass typocheck * fix printing sysroot * Modify final binary * fix wasm assets * remove old link section logic * fix tests * forward manganis export args * fail to evaluate relocatable address * retain all exports in the same pattern as other platforms * Fix adding assets during a wasm hot patch * less nesting and remove logs * fix clippy * log pdb files * read from pdb * print data section contents * print with object * normal windows builds working * fix hot patch windows * clean up logs * fix clippy * clean up assets * use the most recent pdb * fix doc test * fix typo * tiny nits * make bundled a reference instead of a pointer * add helpful comment to impl * match on file format * Fix asset hashing comment --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
f865e3f559
commit
58669f892d
45 files changed
+1174
-762
No files matched your search
@@ -961,10 +961,8 @@ impl BuildRequest {
|
||||
})
|
||||
}
|
||||
|
||||
/// Traverse the target directory and collect all assets from the incremental cache
|
||||
///
|
||||
/// This uses "known paths" that have stayed relatively stable during cargo's lifetime.
|
||||
/// One day this system might break and we might need to go back to using the linker approach.
|
||||
/// Collect the assets from the final executable and modify the binary in place to point to the right
|
||||
/// hashed asset location.
|
||||
fn collect_assets(&self, exe: &Path, ctx: &BuildContext) -> Result<AssetManifest> {
|
||||
// walk every file in the incremental cache dir, reading and inserting items into the manifest.
|
||||
let mut manifest = AssetManifest::default();
|
||||
@@ -972,7 +970,7 @@ impl BuildRequest {
|
||||
// And then add from the exe directly, just in case it's LTO compiled and has no incremental cache
|
||||
if !self.skip_assets {
|
||||
ctx.status_extracting_assets();
|
||||
_ = manifest.add_from_object_path(exe);
|
||||
manifest = super::assets::extract_assets_from_file(exe)?;
|
||||
}
|
||||
|
||||
Ok(manifest)
|
||||
@@ -1109,8 +1107,7 @@ impl BuildRequest {
|
||||
|
||||
// Create a set of all the paths that new files will be bundled to
|
||||
let mut keep_bundled_output_paths: HashSet<_> = assets
|
||||
.assets
|
||||
.values()
|
||||
.assets()
|
||||
.map(|a| asset_dir.join(a.bundled_path()))
|
||||
.collect();
|
||||
|
||||
@@ -1149,8 +1146,8 @@ impl BuildRequest {
|
||||
let mut assets_to_transfer = vec![];
|
||||
|
||||
// Queue the bundled assets
|
||||
for (asset, bundled) in &assets.assets {
|
||||
let from = asset.clone();
|
||||
for bundled in assets.assets() {
|
||||
let from = PathBuf::from(bundled.absolute_source_path());
|
||||
let to = asset_dir.join(bundled.bundled_path());
|
||||
|
||||
// prefer to log using a shorter path relative to the workspace dir by trimming the workspace dir
|
||||
@@ -1381,9 +1378,7 @@ impl BuildRequest {
|
||||
}
|
||||
|
||||
// Now extract the assets from the fat binary
|
||||
artifacts
|
||||
.assets
|
||||
.add_from_object_path(&self.patch_exe(artifacts.time_start))?;
|
||||
self.collect_assets(&self.patch_exe(artifacts.time_start), ctx)?;
|
||||
|
||||
// Clean up the temps manually
|
||||
// todo: we might want to keep them around for debugging purposes
|
||||
@@ -1436,6 +1431,14 @@ impl BuildRequest {
|
||||
"--pie".to_string(),
|
||||
"--experimental-pic".to_string(),
|
||||
]);
|
||||
|
||||
// retain exports so post-processing has hooks to work with
|
||||
for (idx, arg) in original_args.iter().enumerate() {
|
||||
if *arg == "--export" {
|
||||
out_args.push(arg.to_string());
|
||||
out_args.push(original_args[idx + 1].to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This uses "cc" and these args need to be ld compatible
|
||||
@@ -3924,7 +3927,7 @@ impl BuildRequest {
|
||||
}
|
||||
|
||||
// Inject any resources from manganis into the head
|
||||
for asset in assets.assets.values() {
|
||||
for asset in assets.assets() {
|
||||
let asset_path = asset.bundled_path();
|
||||
match asset.options() {
|
||||
AssetOptions::Css(css_options) => {
|
||||
@@ -3954,7 +3957,11 @@ impl BuildRequest {
|
||||
|
||||
// Manually inject the wasm file for preloading. WASM currently doesn't support preloading in the manganis asset system
|
||||
let wasm_source_path = self.wasm_bindgen_wasm_output_file();
|
||||
if let Some(wasm_path) = assets.assets.get(&wasm_source_path) {
|
||||
if let Some(wasm_assets) = assets.get_assets_for_source(&wasm_source_path) {
|
||||
let wasm_path = wasm_assets
|
||||
.iter()
|
||||
.next()
|
||||
.expect("There should be exactly one optimized wasm asset");
|
||||
let wasm_path = wasm_path.bundled_path();
|
||||
head_resources.push_str(&format!(
|
||||
"<link rel=\"preload\" as=\"fetch\" type=\"application/wasm\" href=\"/{{base_path}}/assets/{wasm_path}\" crossorigin>"
|
||||
|
||||
Reference in new issue
Block a user