Skip to content

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

Open
badboy wants to merge 6 commits intomainfrom
glean-sys-generated
Open

Bug 2018944 - glean-sym - a Rust API built on top of the Glean UniFFI C FFI#3426
badboy wants to merge 6 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. it was decided: glean-sym (as in glean-symbols)
  • 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
Comment thread glean-core/glean-sym/src/lib.rs
@badboy badboy force-pushed the glean-sys-generated branch from 23adcc4 to a6d1ef4 Compare March 30, 2026 12:54
@badboy badboy mentioned this pull request Apr 16, 2026
@badboy badboy force-pushed the glean-sys-generated branch 5 times, most recently from e1571f1 to 6a7603a Compare April 17, 2026 17:34
@badboy badboy changed the title Bug 2018944 - glean-sys - a Rust API built on top of the Glean UniFFI C FFI Bug 2018944 - glean-sym - a Rust API built on top of the Glean UniFFI C FFI Apr 22, 2026
@badboy badboy force-pushed the glean-sys-generated branch 4 times, most recently from 48eeb4d to 9b3dd70 Compare April 22, 2026 17:47
badboy added 6 commits April 23, 2026 11:01
…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-sym`, without needing to have Glean in
the same library.
not done yet
@badboy badboy force-pushed the glean-sys-generated branch from 9b3dd70 to 85d08d6 Compare April 23, 2026 15:59
@badboy badboy marked this pull request as ready for review April 23, 2026 15:59
@badboy badboy requested a review from a team as a code owner April 23, 2026 15:59
@badboy badboy requested review from travis79 and removed request for a team April 23, 2026 15:59
@badboy
Copy link
Copy Markdown
Member Author

badboy commented Apr 23, 2026

I would like to land this (experimentally) sometime soon. The plan is to test it out with a metric in appservices, see https://bugzilla.mozilla.org/show_bug.cgi?id=2034534
PoC: badboy/application-services@2c0f79a

Given this is an experiment and not a released crate we can tackle the open questions as we go along, instead of landing the perfectly finished PR.

Copy link
Copy Markdown
Member

@travis79 travis79 left a comment

Choose a reason for hiding this comment

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

Okay, a decent first pass with several questions. Nothing really big aside from the comments in the metrics.rs about the mismatched Double type being bool

Comment on lines +25 to +30
std::mem::transmute(
(crate::GLEAN
.uniffi_glean_core_fn_clone_countermetric)(
std::mem::transmute(self.handle),
&mut call_status,
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We call transmute twice in each of the clone_handle methods in this file, is that needed? Won't the underlying type be u64 on both sides?

}

fn resolve_ffi(&self) -> TokenStream {
quote! { bool }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be bool here? That doesn't seem correct


impl TypeResolver for weedle::term::Boolean {
fn resolve(&self) -> TokenStream {
quote! { i8 }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this mean consumers will need to cast this to a Rust bool?

@@ -0,0 +1,119 @@
// This Source Code Form is subject to the terms of the Mozilla Public
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I take it this is pretty much duplication of types from glean-core? And, if we make changes there we need to make changes here too?

Be sure and document anything like that, preferably in a comment close to where these live so we don't forget to update things in both places.


impl CloneFfiArg<RustBuffer> for RustBuffer {
fn clone_for_ffi(&self) -> RustBuffer {
// SAFETY: trust me, bro.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🙈

use xshell::{Shell, cmd};

#[test]
fn generated_metrics_code_up_to_date() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this test what keeps things in sync? I see you writing to a committed file and then checking for modifications, and that's what I assume. Could you add some documentation comment(s) on what this does?

Comment thread supply-chain/config.toml
version = "0.3.7"
criteria = "safe-to-run"

[[exemptions.prettyplease]]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just out of curiosity, should we document these exemptions anywhere?

Comment thread .circleci/config.yml
command: |
cd samples/glean-sym-test
python3 -m venv ${PWD}/venv
venv/bin/pip install "git+ssh://git@github.com/mozilla/glean_parser@push-lskqopuplvts#egg=glean-parser"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be worth filing a bug to update this once it's no longer experimental? I expect this will eventually be pinned to a proper version

edition = "2024"

[dependencies]
bytes = "1.11.1"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see this being useed anywhere

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