Skip to content

Commit

Permalink
Rust: Split glean-ffi up into 2 crates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
badboy committed Apr 26, 2021
1 parent ba5f1c8 commit c509b74
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ members = [
"glean-core",
"glean-core/ffi",
"glean-core/rlb",
"glean-core/bundle",
]

default-members = [
"glean-core",
"glean-core/ffi",
"glean-core/rlb",
]

exclude = [
Expand Down
2 changes: 1 addition & 1 deletion glean-core/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ afterEvaluate {

cargo {
// The directory of the Cargo.toml to build.
module = '../ffi'
module = '../bundle'

// The Android NDK API level to target.
apiLevel = 21
Expand Down
26 changes: 26 additions & 0 deletions glean-core/bundle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "glean-bundle"
# No need to ever change this version
version = "1.0.0"
authors = ["The Glean Team <glean-team@mozilla.com>"]
edition = "2018"
description = "Static/Dynamic library build of glean-ffi, for use in mobile builds"
repository = "https://github.com/mozilla/glean"
license = "MPL-2.0"

# This crate is never published to crates.io
publish = false

# We use the same name as glean-ffi.
# The Kotlin/Swift/Python bindings will use this name.
[lib]
name = "glean_ffi"
crate-type = ["staticlib", "cdylib"]

[dependencies.glean-ffi]
# No version specified, we build against what's available here.
path = "../ffi"

[features]
# Enable the "safe-mode" Rust storage backend instead of the default LMDB one.
rkv-safe-mode = ["glean-ffi/rkv-safe-mode"]
5 changes: 5 additions & 0 deletions glean-core/bundle/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

pub use glean_ffi;
2 changes: 1 addition & 1 deletion glean-core/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ maintenance = { status = "actively-developed" }

[lib]
name = "glean_ffi"
crate-type = ["lib", "staticlib", "cdylib"]
crate-type = ["lib"]

[dependencies]
ffi-support = "0.4.0"
Expand Down
4 changes: 2 additions & 2 deletions glean-core/ffi/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ glean_app_release: $(SRC) $(OBJECTS_RELEASE) $(HEADERS)
$(CC) $(CFLAGS) -I.. -o $@ $(SRC) $(OBJECTS_RELEASE)

$(OBJECTS_DEBUG): ../src/lib.rs
cargo build
cargo build --package glean-bundle

$(OBJECTS_RELEASE): ../src/lib.rs
cargo build --release
cargo build --package glean-bundle --release
2 changes: 1 addition & 1 deletion glean-core/ios/Glean.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-ffi $PWD/../.. $buildvariant\n";
shellScript = "bash $PWD/../../build-scripts/xc-universal-binary.sh glean-bundle $PWD/../.. $buildvariant\n";
};
BFB59A9723429FC000F40CA8 /* Run Glean SDK generator */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
2 changes: 1 addition & 1 deletion glean-core/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run(self):
"cargo",
"build",
"--package",
"glean-ffi",
"glean-bundle",
"--target",
target,
"--features",
Expand Down

0 comments on commit c509b74

Please sign in to comment.