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

Change Rust integration to emit a single static library #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tschneidereit
Copy link
Member

… instead of compiling multiple crates to static libs and trying to link all of them into the final binary.

This also replaces linking SpiderMonkey's Rust static library with including the required crates into our own library, achieving an end result of having a single static Rust library to link.

And finally, it enables thin-LTO for all libraries: this is in general useful, but even more relevant with more Rust code.

…mpiling multiple crates to static libs and trying to link all of them into the final binary

This also replaces linking SpiderMonkey's Rust static library with including the required crates into our own library, achieving an end result of having a single static Rust library to link.

And finally, it enables thin-LTO for all libraries: this is in general useful, but even more relevant with more Rust code.

Signed-off-by: Till Schneidereit <[email protected]>
@tschneidereit
Copy link
Member Author

@andreiltd it'd be great if you could review this!

/// Configure a panic hook to redirect rust panics to MFBT's MOZ_Crash.
#[no_mangle]
pub extern "C" fn install_rust_hooks() {
panic::set_hook(Box::new(panic_hook));
Copy link
Member

@andreiltd andreiltd Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we care about potentially already defined custom hooks (or a default hook) and wrapping it with the new one?

E.g.:

    let previous_hook = panic::take_hook();

    panic::set_hook(Box::new(move |info: &PanicInfo| {
        panic_hook(info);
        previous_hook(info);
    }));

@@ -2,9 +2,6 @@
resolver = "2"
members = ["fuzz"]

[lib]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also strip following from this file?

[profile.release]
lto = true
panic = 'abort'

[profile.dev]
lto = true
panic = 'abort'

Copy link
Member

@andreiltd andreiltd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected wpt passes are indeed unexpected :)

@tschneidereit
Copy link
Member Author

Unexpected wpt passes are indeed unexpected :)

Initially yes. Took some digging, but I found the cause: the rust-url crate has a lock file, which we're now not using anymore. And so the url crate was updated from 2.5.2 to 2.5.4.

So far, so good. However, the question is if we need a lock file. And if so, how do we even go about getting one? I guess we could keep one in the template crate and copy it over. If it doesn't cover everything, it'll be added to during the build, which seems okay.

@andreiltd
Copy link
Member

Would it be possible to have a workspace Cargo.toml in the project root directory that cmake will pick up and build everything to a single library, and then maintain only a top level lock file?

@tschneidereit
Copy link
Member Author

It would be, but then we'd spread things out across the template crate and this top-level one, which is why I was shying away from it so far. But yeah, maybe that makes most sense to do. I'll look into it

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

Successfully merging this pull request may close these issues.

2 participants