Skip to content

Bug 2018944 - glean-sys - a Rust API built on top of the Glean UniFFI C FFI#3426

Draft
badboy wants to merge 3 commits intomainfrom
glean-sys-generated
Draft

Bug 2018944 - glean-sys - a Rust API built on top of the Glean UniFFI C FFI#3426
badboy wants to merge 3 commits intomainfrom
glean-sys-generated

Conversation

@badboy
Copy link
Copy Markdown
Member

@badboy badboy commented Mar 30, 2026

This small patch on a-s makes use of the new glean-sys crate: mozilla/application-services@main...badboy:application-services:glean-dylib

Todo:

  • Naming! Not sure I like glean-sys.
  • Testing. Not clear how we will do that. Probably some sample crate that uses glean-sys and we inject a libxul.so into it at test time
  • glean-sys/src/metrics.rs is generated. Currently by a test. That has a bit of a problem that you need to compile the code to generate the code, which breaks if the code doesn't compile. Might want to have a non-test way to generate that code.
  • libxul.so is hard-coded. Ok for manual testing in Fenix, not sure we want to ship that as-is
  • No way to ensure we're not the first ones loading libxul.
  • Should we have the UniFFI-alike runtime checks? (like the version check)
  • Extend glean_parser (and glean-build) to generate the correct code usable with glean-sys
  • Dependency vetting
  • Rust minimum version bump probably necessary (or we need to exclude glean-sys)

@badboy badboy force-pushed the glean-sys-generated branch 2 times, most recently from dab03d7 to 23adcc4 Compare March 30, 2026 11:31
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "windows")))]
let name = "libxul.so";

let library = match unsafe { libloading::Library::new(name) } {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fwiw, I tried it with libloading::os::unix::Library::this(), but then it couldn't find the symbols, even though I'm certain libxul was already loaded. This might need some testing to ensure we're not the first ones loading libxul and that loading it again doesn't have any other negative impact.

badboy added 3 commits March 30, 2026 14:53
…ated code over FFI

This will be used later by glean-sys to build a Rust API via C FFI.
…C FFI

This loads `libxul.so` (currently hard-coded), looks up the required symbols and wraps that in
a nice Rust API.
Other crates can depend on `glean-sys`, without needing to have Glean in
the same library.
@badboy badboy force-pushed the glean-sys-generated branch from 23adcc4 to a6d1ef4 Compare March 30, 2026 12:54
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.

1 participant