@@ -842,15 +842,6 @@ impl BuildRequest {
842842 None => bundle. profile_name ( args. release ) ,
843843 } ;
844844
845- // Warn if the user is trying to build with strip and using manganis
846- Self :: warn_manganis_strip (
847- & workspace. krates ,
848- & workspace. cargo_toml ,
849- main_package,
850- & profile,
851- args. release ,
852- ) ;
853-
854845 // Determine if we should codesign
855846 let should_codesign =
856847 args. codesign || device. is_some ( ) || args. apple_entitlements . is_some ( ) ;
@@ -1082,6 +1073,7 @@ impl BuildRequest {
10821073 BuildMode :: Base { .. } | BuildMode :: Fat => {
10831074 ctx. status_start_bundle ( ) ;
10841075
1076+ self . strip_binary ( & artifacts) . await ?;
10851077 self . write_executable ( ctx, & artifacts. exe , & mut artifacts. assets )
10861078 . await
10871079 . context ( "Failed to write executable" ) ?;
@@ -3627,32 +3619,19 @@ impl BuildRequest {
36273619 } )
36283620 }
36293621
3630- /// Return the platforms that are enabled for the package
3631- ///
3632- /// Ideally only one platform is enabled but we need to be able to
3633- pub ( crate ) fn warn_manganis_strip (
3634- krates : & krates:: Krates ,
3635- cargo_toml : & cargo_toml:: Manifest ,
3636- main_package : & krates:: cm:: Package ,
3637- profile : & str ,
3638- release : bool ,
3639- ) {
3640- let Some ( id) = krates. nid_for_kid ( & main_package. id . clone ( ) . into ( ) ) else {
3641- return ;
3642- } ;
3643- let dependencies = krates. direct_dependencies ( id) ;
3644- if !dependencies. iter ( ) . any ( |dep| dep. krate . name == "manganis" ) {
3645- return ;
3646- }
3647-
3648- let ( profile_name, profile) = match ( cargo_toml. profile . custom . get ( profile) , release) {
3649- ( Some ( custom_profile) , _) => ( profile, Some ( custom_profile) ) ,
3650- ( _, true ) => ( "release" , cargo_toml. profile . release . as_ref ( ) ) ,
3651- ( _, false ) => ( "dev" , cargo_toml. profile . dev . as_ref ( ) ) ,
3622+ /// Checks the strip setting for the package, resolving profiles recursively
3623+ pub ( crate ) fn get_strip_setting ( & self ) -> StripSetting {
3624+ let cargo_toml = & self . workspace . cargo_toml ;
3625+ let profile = & self . profile ;
3626+ let release = self . release ;
3627+ let profile = match ( cargo_toml. profile . custom . get ( profile) , release) {
3628+ ( Some ( custom_profile) , _) => Some ( custom_profile) ,
3629+ ( _, true ) => cargo_toml. profile . release . as_ref ( ) ,
3630+ ( _, false ) => cargo_toml. profile . dev . as_ref ( ) ,
36523631 } ;
36533632
36543633 let Some ( profile) = profile else {
3655- return ;
3634+ return StripSetting :: None ;
36563635 } ;
36573636
36583637 // Get the strip setting from the profile or the profile it inherits from
@@ -3673,15 +3652,11 @@ impl BuildRequest {
36733652 }
36743653
36753654 let Some ( strip) = get_strip ( profile, & cargo_toml. profile ) else {
3676- // If the profile doesn't have a strip option, we don't need to warn
3677- return ;
3655+ // If the profile doesn't have a strip option, return None
3656+ return StripSetting :: None ;
36783657 } ;
36793658
3680- if matches ! ( strip, cargo_toml:: StripSetting :: Symbols ) {
3681- tracing:: warn!(
3682- "The `strip` option is enabled in the `{profile_name}` profile. This may cause manganis assets to be stripped from the final binary." ,
3683- ) ;
3684- }
3659+ strip
36853660 }
36863661
36873662 pub ( crate ) fn renderer_enabled_by_dioxus_dependency (
@@ -3988,6 +3963,31 @@ impl BuildRequest {
39883963 Ok ( ( ) )
39893964 }
39903965
3966+ /// Strip the final binary after extracting all assets with rustc-objcopy
3967+ async fn strip_binary ( & self , artifacts : & BuildArtifacts ) -> Result < ( ) > {
3968+ // Never strip the binary if we are going to bundle split it
3969+ if self . wasm_split {
3970+ return Ok ( ( ) ) ;
3971+ }
3972+ let exe = & artifacts. exe ;
3973+ // https://github.com/rust-lang/rust/blob/cb80ff132a0e9aa71529b701427e4e6c243b58df/compiler/rustc_codegen_ssa/src/back/linker.rs#L1433-L1443
3974+ let strip_arg = match self . get_strip_setting ( ) {
3975+ StripSetting :: Debuginfo => Some ( "--strip-debug" ) ,
3976+ StripSetting :: Symbols => Some ( "--strip-all" ) ,
3977+ StripSetting :: None => None ,
3978+ } ;
3979+ if let Some ( strip_arg) = strip_arg {
3980+ let rustc_objcopy = self . workspace . rustc_objcopy ( ) ;
3981+ let mut command = Command :: new ( rustc_objcopy) ;
3982+ command. arg ( strip_arg) . arg ( exe) . arg ( exe) ;
3983+ let output = command. output ( ) . await ?;
3984+ if !output. status . success ( ) {
3985+ return Err ( anyhow:: anyhow!( "Failed to strip binary" ) ) ;
3986+ }
3987+ }
3988+ Ok ( ( ) )
3989+ }
3990+
39913991 /// Check if assets should be pre_compressed. This will only be true in release mode if the user
39923992 /// has enabled pre_compress in the web config.
39933993 fn should_pre_compress_web_assets ( & self , release : bool ) -> bool {
@@ -4036,19 +4036,16 @@ impl BuildRequest {
40364036
40374037 // Prepare our configuration
40384038 //
4039- // we turn off debug symbols in dev mode but leave them on in release mode (weird!) since
4040- // wasm-opt and wasm-split need them to do better optimizations.
4039+ // we turn on debug symbols in dev mode
40414040 //
40424041 // We leave demangling to false since it's faster and these tools seem to prefer the raw symbols.
40434042 // todo(jon): investigate if the chrome extension needs them demangled or demangles them automatically.
4044- let will_wasm_opt = self . release || self . wasm_split ;
40454043 let keep_debug = self . config . web . wasm_opt . debug
40464044 || self . debug_symbols
40474045 || self . wasm_split
40484046 || !self . release
4049- || will_wasm_opt
40504047 || ctx. mode == BuildMode :: Fat ;
4051- let keep_names = will_wasm_opt || ctx. mode == BuildMode :: Fat ;
4048+ let keep_names = self . wasm_split || ctx. mode == BuildMode :: Fat ;
40524049 let demangle = false ;
40534050 let wasm_opt_options = WasmOptConfig {
40544051 memory_packing : self . wasm_split ,
@@ -4086,10 +4083,6 @@ impl BuildRequest {
40864083 if should_bundle_split {
40874084 ctx. status_splitting_bundle ( ) ;
40884085
4089- if !will_wasm_opt {
4090- bail ! ( "Bundle splitting should automatically enable wasm-opt, but it was not enabled." ) ;
4091- }
4092-
40934086 // Load the contents of these binaries since we need both of them
40944087 // We're going to use the default makeLoad glue from wasm-split
40954088 let original = std:: fs:: read ( exe) ?;
@@ -5252,6 +5245,10 @@ __wbg_init({{module_or_path: "/{}/{wasm_path}"}}).then((wasm) => {{
52525245 }
52535246 }
52545247
5248+ // Always disable stripping so symbols still exist for the asset system. We will apply strip manually
5249+ // after assets are built
5250+ args. push ( format ! ( r#"profile.{profile}.strip=false"# ) ) ;
5251+
52555252 // Prepend --config to each argument
52565253 args. into_iter ( )
52575254 . flat_map ( |arg| [ "--config" . to_string ( ) , arg] )
0 commit comments