Skip to content

Instantly share code, notes, and snippets.

@bonzini
Created March 24, 2026 09:07
Show Gist options
  • Select an option

  • Save bonzini/b9a985a5dae2008c89f1265ca7e2bf25 to your computer and use it in GitHub Desktop.

Select an option

Save bonzini/b9a985a5dae2008c89f1265ca7e2bf25 to your computer and use it in GitHub Desktop.
fc-cargo.patch
diff --git a/Cargo.toml b/Cargo.toml
index 0b7468de..faa0c123 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,4 +15,9 @@ bytemuck_derive = "1"
[lib]
+crate-type = ["staticlib"]
path = "fc-fontations/mod.rs"
+
+[lints.rust]
+unsafe_op_in_unsafe_fn = "deny"
+warnings = "deny"
diff --git a/fc-fontations/meson.build b/fc-fontations/meson.build
index 7dbb5764..9533b1ee 100644
--- a/fc-fontations/meson.build
+++ b/fc-fontations/meson.build
@@ -2,6 +2,7 @@ fontations = get_option('fontations')
if (fontations.enabled())
rust = import('rust')
+ cargo = rust.workspace()
generated_fontconfig = rust.bindgen(
input: fontconfig_h,
@@ -34,18 +35,17 @@ if (fontations.enabled())
c_args: ['-DBINDGEN_IGNORE_VISIBILITY=1', '-DFC_NO_MT=1'],
)
- fontations_bindings_lib = static_library(
- 'fontconfig_bindings',
- sources: [generated_fontconfig],
- rust_abi: 'rust',
- )
+ fontconfig_bindings_pkg = cargo.package('fontconfig-bindings')
+ fontconfig_bindings_lib = fontconfig_bindings_pkg.library(
+ structured_sources(generated_fontconfig))
+ fontconfig_bindings_pkg.override_dependency(
+ declare_dependency(link_with: fontconfig_bindings_lib))
- fcint_bindings_lib = static_library(
- 'fcint_bindings',
- sources: [generated_fcint],
- rust_abi: 'rust',
- link_with: [fontations_bindings_lib],
- )
+ fcint_bindings_pkg = cargo.package('fcint-bindings')
+ fcint_bindings_lib = fcint_bindings_pkg.library(
+ structured_sources(generated_fcint))
+ fcint_bindings_pkg.override_dependency(
+ declare_dependency(link_with: fcint_bindings_lib))
fontations_query_lib = static_library(
'fc_fontations_query',
@@ -53,25 +53,11 @@ if (fontations.enabled())
sources: ['../src/fcfontations.c', fcstdint_h, fclang_h, alias_headers],
)
- fc_fontations = static_library(
- 'fc_fontations',
- sources: ['mod.rs'],
+ fc_fontations = cargo.package().library(
link_with: [
- fontations_bindings_lib,
- fcint_bindings_lib,
pattern_lib,
fontations_query_lib,
],
- rust_args: ['-Dunsafe-op-in-unsafe-fn', '-Dwarnings'],
- rust_abi: 'c',
- dependencies: [
- dependency('skrifa-0.39-rs'),
- dependency('read-fonts-0.36-rs'),
- dependency('font-types-0.10-rs'),
- dependency('libc-0.2-rs'),
- ],
install: true,
-
)
-
-endif
\ No newline at end of file
+endif
@drott

drott commented Mar 24, 2026

Copy link
Copy Markdown

Interesting, this looks like a simplifcation - how is it possible to remove the listed dependencies? Where does cargo.package() infer those from?

@bonzini

bonzini commented Mar 24, 2026

Copy link
Copy Markdown
Author

It's easiest if you take a look at the spec :) mesonbuild/meson#14639

@drott

drott commented Mar 24, 2026

Copy link
Copy Markdown

Right, thanks, looks like a good improvement for the FontConfig use case.

@bonzini

bonzini commented Mar 24, 2026

Copy link
Copy Markdown
Author

Ironically I had no idea that Fontconfig was using Rustc from Meson (and with Cargo subprojects at that), and only found out because of the breakage in 1.10.2 ๐Ÿ˜‡

@drott

drott commented Mar 24, 2026

Copy link
Copy Markdown

We use the Rust indexing code based on Fontations from FontConfig in Chromium, as we have removed FreeType. FontConfig does not ship the Rust based font scanning/indexing on Linux distributions yet, but I'd hope that happens someday.

@bonzini

bonzini commented Mar 24, 2026

Copy link
Copy Markdown
Author

I'm all for more Rust/Meson projects appearing in distros. If you have any pointers as to how Chromium uses Rust (does it build FC/Fontations with GN?) I can look at it and try to match the features in Meson.

@drott

drott commented Mar 24, 2026

Copy link
Copy Markdown

Yes, we have good Rust support in GN. For FontConfig that's here:
https://source.chromium.org/chromium/chromium/src/+/main:third_party/fontconfig/BUILD.gn

The reason FC is not shipping the Rust code to distros yet is rather a few missing features than particular build system support issues, I believe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment