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

Compress folder in OUT_DIR #9

Closed
stevefan1999-personal opened this issue Aug 13, 2023 · 8 comments
Closed

Compress folder in OUT_DIR #9

stevefan1999-personal opened this issue Aug 13, 2023 · 8 comments

Comments

@stevefan1999-personal
Copy link

Would there likely be an example for that?

@evolutics
Copy link
Owner

Hi @stevefan1999-personal,

There's an example that compresses files of a folder, then includes them. It uses the library include-flate – see also the mentioned trade-offs there.

Let me know if that helps.

@stevefan1999-personal
Copy link
Author

@evolutics Unfortunately, that doesn't seems to work with OUT_DIR

@evolutics
Copy link
Owner

Interesting! Can you provide more details (code, error, environment, etc.), please?

@stevefan1999-personal
Copy link
Author

@evolutics Yes. Here's a reproduction: stevefan1999-personal/iftree-reproduce (github.com)

@evolutics
Copy link
Owner

Thank you very much for the full reproduction case.

include-flate doesn't support absolute paths, see SOF3/include-flate#12. You'd have to use $relative_path in your code.

However, then there's the issue that relative paths generated by Iftree are relative to the Iftree base folder, which is "${OUT_DIR}/merged/" in your case. When accessing these files, their paths are interpreted as relative to the root of your repository (e.g., iftree-reproduce/bar, iftree-reproduce/foo), causing the "no such file" errors.

I need to think about how to best resolve this.

@stevefan1999-personal
Copy link
Author

I made it! Here's how it looked:

use derivative::Derivative;
use once_cell::sync::Lazy;
use qp_trie::{wrapper::BString, Trie};

macro_rules! visit_base {
    ($length:literal, $($contents:expr)*) => {
        pub static ASSETS: Lazy<Trie<BString, Asset>> = Lazy::new(|| {
            [$($contents,)*].into_iter().collect()
        });
    };
}

macro_rules! visit_file {
    (
        $name:literal,
        $id:ident,
        $index:literal,
        $relative_path:literal,
        $absolute_path:literal
    ) => {

        (
            $relative_path.into(),
            Asset {
                relative_path:  $relative_path,
                contents_bytes: {
                    include_flate::flate!(pub static DATA: [u8] from $absolute_path);
                    &DATA
                },
            },
        )
    };
}

#[iftree::include_file_tree(
    "
root_folder_variable = 'OUT_DIR'
base_folder = 'include/'
paths = '/**'

[[template]]
visit_base = 'visit_base'
visit_file = 'visit_file'
"
)]
#[derive(Derivative)]
#[derivative(Debug)]
pub struct Asset {
    relative_path:      &'static str,
    #[derivative(Debug = "ignore")]
    pub contents_bytes: &'static [u8],
}

Need to downgrade include-flate to 0.1.4 though

@stevefan1999-personal
Copy link
Author

stevefan1999-personal commented Aug 13, 2023

Thank you very much for the full reproduction case.

include-flate doesn't support absolute paths, see SOF3/include-flate#12. You'd have to use $relative_path in your code.

However, then there's the issue that relative paths generated by Iftree are relative to the Iftree base folder, which is "${OUT_DIR}/merged/" in your case. When accessing these files, their paths are interpreted as relative to the root of your repository (e.g., iftree-reproduce/bar, iftree-reproduce/foo), causing the "no such file" errors.

I need to think about how to best resolve this.

Hmm, maybe add a random number in base folder as a prefix, and expect to copy all the files over there?

Like:

root_folder_variable = 'OUT_DIR'
base_folder = '$SEED_FROM_BUILD_RS/include/'
paths = '/**'

[[template]]
visit_base = 'visit_base'
visit_file = 'visit_file'

@evolutics
Copy link
Owner

Thanks for sharing.

Nice that you've found a solution for your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants