diff --git a/cli-support/src/linker_intercept.rs b/cli-support/src/linker_intercept.rs index 6390f31..3fe10c8 100644 --- a/cli-support/src/linker_intercept.rs +++ b/cli-support/src/linker_intercept.rs @@ -13,15 +13,12 @@ const MG_WORKDIR_ARG_NAME: &str = "mg-working-dir;"; pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec)> { let args = args.collect::>(); - // let data = format!("{:?}", args); - // fs::write("./mg-linker-intercept-out-args", data).unwrap(); - // println!("{:?}", args); - let mut working_dir = std::env::current_dir().unwrap(); // Check if we were provided with a command file. let mut is_command_file = None; for arg in args.iter() { + // On windows the linker args are passed in a file that is referenced by `@` if arg.starts_with('@') { is_command_file = Some(arg.clone()); break; @@ -29,6 +26,13 @@ pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec)> } let linker_args = match is_command_file { + // On unix/linux/mac the linker args are passed directly. + None => { + let args = &args[1..args.len()]; + Vec::from(args) + } + + // Handle windows here - uf16 and utf8 files are supported. Some(arg) => { let path = arg.trim().trim_start_matches('@'); let file_binary = fs::read(path).unwrap(); @@ -52,6 +56,7 @@ pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec)> let lines = content.lines(); for line in lines { + // Remove quotes from the line - windows link args files are quoted let line_parsed = line.to_string(); let line_parsed = line_parsed.trim_end_matches('\"').to_string(); let line_parsed = line_parsed.trim_start_matches('\"').to_string(); @@ -61,16 +66,14 @@ pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec)> linker_args } - None => { - let args = &args[1..args.len()]; - Vec::from(args) - } }; // Parse through linker args for `.o` or `.rlib` files. let mut object_files: Vec = Vec::new(); for item in linker_args { // Get the working directory so it isn't lost. + // when rust calls the linker it doesn't pass the working dir so we need to recover it + // "MG_WORKDIR_ARG_NAME;dir" if item.starts_with(MG_WORKDIR_ARG_NAME) { let split: Vec<_> = item.split(';').collect(); working_dir = PathBuf::from(split[1]); diff --git a/macro/src/file.rs b/macro/src/file.rs index 791bc53..edb0be6 100644 --- a/macro/src/file.rs +++ b/macro/src/file.rs @@ -41,8 +41,10 @@ impl ToTokens for FileAssetParser { let link_section = generate_link_section(self.asset.clone()); tokens.extend(quote! { - #link_section - #file_name + { + #link_section + #file_name + } }) } } diff --git a/macro/src/font.rs b/macro/src/font.rs index f1d85ff..588389b 100644 --- a/macro/src/font.rs +++ b/macro/src/font.rs @@ -173,8 +173,10 @@ impl ToTokens for FontAssetParser { let link_section = generate_link_section(self.asset.clone()); tokens.extend(quote! { - #link_section - #file_name + { + #link_section + #file_name + } }) } } diff --git a/macro/src/image.rs b/macro/src/image.rs index 1d0e345..0f390aa 100644 --- a/macro/src/image.rs +++ b/macro/src/image.rs @@ -306,8 +306,10 @@ impl ToTokens for ImageAssetParser { let link_section = generate_link_section(self.asset.clone()); tokens.extend(quote! { - #link_section - manganis::ImageAsset::new(#file_name).with_preview(#low_quality_preview) + { + #link_section + manganis::ImageAsset::new(#file_name).with_preview(#low_quality_preview) + } }) } } diff --git a/src/lib.rs b/src/lib.rs index 018b0d2..d7c5f70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,36 +297,3 @@ mod __private { impl ForMgMacro for ImageAssetBuilder {} impl ForMgMacro for FontAssetBuilder {} impl ForMgMacro for &'static str {} - -// // expose the manganis section to the rust linker -// // this have to be in sync with `common/src/linker.rs` -// extern "Rust" { -// #[cfg_attr( -// any( -// target_os = "none", -// target_os = "linux", -// target_os = "android", -// target_os = "fuchsia", -// target_os = "psp", -// target_os = "freebsd", -// target_os = "wasm" -// ), -// link_name = "__start_manganis" -// )] -// #[cfg_attr( -// any(target_os = "macos", target_os = "ios", target_os = "tvos"), -// link_name = "\x01section$start$__DATA$manganis" -// )] -// #[cfg_attr(target_os = "windows", link_name = "mg_s")] -// #[cfg_attr(target_os = "illumos", link_name = "__start_set_manganis")] - -// static MANGANIS_START: u8; -// } - -// /// call this function in your main to use manganis. -// /// This will make rust include all the assets for you -// pub fn init() { -// unsafe { -// assert!(MANGANIS_START != 0); -// } -// }