Skip to content

Commit 40f1b3a

Browse files
committed
Rust: Split glean-ffi up into 2 crates
glean-ffi carries all the no_mangle extern "C" definitions of our FFI layer. This is getting included in mozilla-central soon. However we can't have crates that are build as a `cdylib` as dependencies in mozilla-central, as this will then produce said `cdylib` during the build, which breaks at least on one build target. We don't need that `cdylib` published, we only need it for builds we ship ourselves: Kotlin, Swift & Python. Therefore we split this part into a `glean-bundle` crate which itself will generate a `cdylib` by the name `libglean_ffi`. Our builds only need to reference that other workspace member, but don't need to change what library they are loading. Now `glean-ffi` is a plain ol' Rust crate and we can use that in mozilla-central.
1 parent ba5f1c8 commit 40f1b3a

File tree

8 files changed

+49
-4
lines changed

8 files changed

+49
-4
lines changed

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ members = [
44
"glean-core",
55
"glean-core/ffi",
66
"glean-core/rlb",
7+
"glean-core/bundle",
8+
]
9+
10+
default-members = [
11+
"glean-core",
12+
"glean-core/ffi",
13+
"glean-core/rlb",
714
]
815

916
exclude = [

glean-core/android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ afterEvaluate {
140140

141141
cargo {
142142
// The directory of the Cargo.toml to build.
143-
module = '../ffi'
143+
module = '../bundle'
144144

145145
// The Android NDK API level to target.
146146
apiLevel = 21

glean-core/bundle/Cargo.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "glean-bundle"
3+
# No need to ever change this version
4+
version = "1.0.0"
5+
authors = ["Jan-Erik Rediger <[email protected]>"]
6+
edition = "2018"
7+
description = "Static/Dynamic library build of glean-ffi, for use in mobile builds"
8+
repository = "https://github.com/mozilla/glean"
9+
license = "MPL-2.0"
10+
11+
# This crate is never published to crates.io
12+
publish = false
13+
14+
# We use the same name as glean-ffi.
15+
# The Kotlin/Swift/Python bindings will use this name.
16+
[lib]
17+
name = "glean_ffi"
18+
crate-type = ["staticlib", "cdylib"]
19+
20+
[dependencies.glean-ffi]
21+
# No version specified, we build against what's available here.
22+
path = "../ffi"
23+
24+
[features]
25+
# Enable the "safe-mode" Rust storage backend instead of the default LMDB one.
26+
rkv-safe-mode = ["glean-ffi/rkv-safe-mode"]

glean-core/bundle/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4+
5+
pub use glean_ffi;

glean-core/ffi/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ maintenance = { status = "actively-developed" }
2424

2525
[lib]
2626
name = "glean_ffi"
27-
crate-type = ["lib", "staticlib", "cdylib"]
27+
crate-type = ["lib"]
2828

2929
[dependencies]
3030
ffi-support = "0.4.0"

glean-core/ios/Glean.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
);
524524
runOnlyForDeploymentPostprocessing = 0;
525525
shellPath = /bin/sh;
526-
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-ffi $PWD/../.. $buildvariant\n";
526+
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-bundle $PWD/../.. $buildvariant\n";
527527
};
528528
BFB59A9723429FC000F40CA8 /* Run Glean SDK generator */ = {
529529
isa = PBXShellScriptBuildPhase;

glean-core/python/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def run(self):
183183
"cargo",
184184
"build",
185185
"--package",
186-
"glean-ffi",
186+
"glean-bundle",
187187
"--target",
188188
target,
189189
"--features",

0 commit comments

Comments
 (0)