Skip to content

Commit

Permalink
Some light fixes to blocks and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp committed Jun 28, 2024
1 parent 7f12ba3 commit 39c2736
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 47 deletions.
19 changes: 11 additions & 8 deletions cli-support/src/linker_intercept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,26 @@ const MG_WORKDIR_ARG_NAME: &str = "mg-working-dir;";
pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec<PathBuf>)> {
let args = args.collect::<Vec<String>>();

// 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 `@<file>`
if arg.starts_with('@') {
is_command_file = Some(arg.clone());
break;
}
}

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();
Expand All @@ -52,6 +56,7 @@ pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec<PathBuf>)>
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();
Expand All @@ -61,16 +66,14 @@ pub fn linker_intercept(args: std::env::Args) -> Option<(PathBuf, Vec<PathBuf>)>

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<PathBuf> = 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]);
Expand Down
6 changes: 4 additions & 2 deletions macro/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
}
6 changes: 4 additions & 2 deletions macro/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
}
6 changes: 4 additions & 2 deletions macro/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
33 changes: 0 additions & 33 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
// }

0 comments on commit 39c2736

Please sign in to comment.