Skip to content

Commit 7cb40ee

Browse files
committed
Add build tooling so we can work in mozilla-central.
Most of the files here are ignored when in application-services, but when copied into mozilla-central they enable "mach build" to build our megazord and other tooling.
1 parent 8501512 commit 7cb40ee

File tree

10 files changed

+321
-0
lines changed

10 files changed

+321
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "mozilla/Types.h"
7+
8+
// This seems sad?
9+
// If we could get a stub .rs we could use `tabs::uniffi_reexport_scaffolding!();` etc,
10+
// but here we are.
11+
// To get the symbols from our static lib we need to refer to a symbol from each crate within it.
12+
// This is an arbitrary choice - any symbol will do, but we chose these because every uniffi crate has it.
13+
extern int MOZ_EXPORT ffi_autofill_uniffi_contract_version();
14+
extern int MOZ_EXPORT ffi_crashtest_uniffi_contract_version();
15+
extern int MOZ_EXPORT ffi_fxa_client_uniffi_contract_version();
16+
extern int MOZ_EXPORT ffi_init_rust_components_uniffi_contract_version();
17+
extern int MOZ_EXPORT ffi_logins_uniffi_contract_version();
18+
extern int MOZ_EXPORT ffi_merino_uniffi_contract_version();
19+
extern int MOZ_EXPORT ffi_nimbus_uniffi_contract_version();
20+
extern int MOZ_EXPORT ffi_places_uniffi_contract_version();
21+
extern int MOZ_EXPORT ffi_push_uniffi_contract_version();
22+
extern int MOZ_EXPORT ffi_relay_uniffi_contract_version();
23+
extern int MOZ_EXPORT ffi_remote_settings_uniffi_contract_version();
24+
extern int MOZ_EXPORT ffi_rust_log_forwarder_uniffi_contract_version();
25+
extern int MOZ_EXPORT ffi_search_uniffi_contract_version();
26+
extern int MOZ_EXPORT ffi_suggest_uniffi_contract_version();
27+
extern int MOZ_EXPORT ffi_sync15_uniffi_contract_version();
28+
extern int MOZ_EXPORT ffi_sync_manager_uniffi_contract_version();
29+
extern int MOZ_EXPORT ffi_tabs_uniffi_contract_version();
30+
31+
// far out, this is crazy - without this, only the search _NAMESPACE meta comes in,
32+
// meaning uniffi ends up generating a completely empty kotlin module for search.
33+
// Looking at `nm obj-dir/.../libsearch-*.rlib` you can see many symbols
34+
// are in a different .o - this symbol is one taken randomly from the .o with
35+
// the missing symbols, and they all happily come in.
36+
// W T A F.
37+
extern int MOZ_EXPORT uniffi_search_checksum_constructor_searchengineselector_new();
38+
39+
void _local_megazord_dummy_symbol() {
40+
ffi_autofill_uniffi_contract_version();
41+
ffi_crashtest_uniffi_contract_version();
42+
ffi_fxa_client_uniffi_contract_version();
43+
ffi_init_rust_components_uniffi_contract_version();
44+
ffi_logins_uniffi_contract_version();
45+
ffi_merino_uniffi_contract_version();
46+
ffi_nimbus_uniffi_contract_version();
47+
ffi_places_uniffi_contract_version();
48+
ffi_push_uniffi_contract_version();
49+
ffi_relay_uniffi_contract_version();
50+
ffi_remote_settings_uniffi_contract_version();
51+
ffi_rust_log_forwarder_uniffi_contract_version();
52+
ffi_search_uniffi_contract_version();
53+
ffi_suggest_uniffi_contract_version();
54+
ffi_sync15_uniffi_contract_version();
55+
ffi_sync_manager_uniffi_contract_version();
56+
ffi_tabs_uniffi_contract_version();
57+
uniffi_search_checksum_constructor_searchengineselector_new();
58+
}

megazords/fenix-dylib/moz.build

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
# There are 2 parts to our megazord - a staticlib in megazords/full, then this
6+
# build file to create the final dyib .so
7+
# See the comments in megazords/full/moz.build.
8+
9+
UNIFIED_SOURCES += [
10+
"megazord_stub.c",
11+
]
12+
13+
# This name confusion is a reflection of the 2 megazord parts. It should be
14+
# fixed after we land in m-c.
15+
SharedLibrary("megazord-so")
16+
SHARED_LIBRARY_NAME = "megazord"
17+
18+
USE_LIBS += ["megazord", "mozpkix", "nspr"]
19+
20+
# copy-pasta from other moz.build files.
21+
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
22+
OS_LIBS += ["-framework CoreFoundation"]
23+
elif CONFIG["OS_TARGET"] == "WINNT":
24+
OS_LIBS += [
25+
"advapi32",
26+
"bcrypt",
27+
"mswsock",
28+
"ntdll",
29+
"shell32",
30+
"user32",
31+
"userenv",
32+
"wsock32",
33+
"ws2_32",
34+
"winmm",
35+
]

megazords/full/moz.build

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
# Note that this crate, when used in app-services, directly creates the cdylib.
8+
# However, in moz-central it builds a staticlib. A new target in `../fenix-dylib`
9+
# takes this as a dep and creates the final cdylib.
10+
USE_LIBS += ["nss"]
11+
12+
UNIFIED_SOURCES += [
13+
"stub.cpp",
14+
]
15+
16+
# This is the name of the .a file created.
17+
RustLibrary("megazord")
18+
19+
# XXX - this doesn't really work - the tests fail due to missing `nss3`?
20+
RUST_TESTS = [
21+
"megazord",
22+
]

megazords/full/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use std::ffi::CString;
99
use std::os::raw::c_char;
1010

11+
// NOTE if you add or remove crates below here, please make a corresponding change in ../fenix-dylib/megazord_stub.c
1112
pub use autofill;
1213
pub use crashtest;
1314
pub use error_support;
@@ -27,6 +28,8 @@ pub use sync_manager;
2728
pub use tabs;
2829
pub use tracing_support;
2930
pub use viaduct;
31+
// NOTE if you add or remove crates above here, please make a corresponding change in ../fenix-dylib/megazord_stub.c
32+
3033
// TODO: Uncomment this code when webext-storage component is integrated in android
3134
// pub use webext_storage;
3235

megazords/full/stub.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
// This is an intentionally empty file. It is necessary for the build system to
7+
// successfully convert a static rust library into a dynamic library on
8+
// Windows.

megazords/ios-rust/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# May be built outside of a workspace, leaving extra junk behind.
2+
Cargo.lock
3+
target

moz.build

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
# Note that this builds the cdylib for our megazord. See the comments
6+
# in megazords/full/moz.build.
7+
8+
UNIFIED_SOURCES += [
9+
"megazord_stub.c",
10+
]
11+
12+
# This name confusion is a reflection of some of the above. It should be
13+
# fixed, but may be easier/better to fix once in m-c.
14+
SharedLibrary("megazord-so")
15+
SHARED_LIBRARY_NAME = "megazord"
16+
17+
USE_LIBS += ["megazord", "mozpkix", "nspr"]
18+
19+
# copy-pasta from other moz.build files, are these the correct checks?
20+
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
21+
OS_LIBS += ["-framework CoreFoundation"]
22+
elif CONFIG["OS_TARGET"] == "WINNT":
23+
OS_LIBS += [
24+
"advapi32",
25+
"bcrypt",
26+
"mswsock",
27+
"ntdll",
28+
"shell32",
29+
"user32",
30+
"userenv",
31+
"wsock32",
32+
"ws2_32",
33+
"winmm",
34+
]

tools/embedded-uniffi-bindgen/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ authors = ["The Firefox Sync Developers <[email protected]>"]
55
edition = "2021"
66
license = "MPL-2.0"
77

8+
# A bin target needed when used in m-c.
9+
[[bin]]
10+
name = "embedded-uniffi-bindgen"
11+
812
[dependencies]
913
uniffi = { version = "0.29.0", features = ["cli"] }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2+
# vim: set filetype=python:
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
7+
HOST_RUST_PROGRAMS = ["embedded-uniffi-bindgen"]
8+
9+
# copy-pasta from other moz.build file.
10+
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
11+
OS_LIBS += ["-framework CoreFoundation"]
12+
elif CONFIG["OS_TARGET"] == "WINNT":
13+
OS_LIBS += [
14+
"advapi32",
15+
"wsock32",
16+
"ws2_32",
17+
"mswsock",
18+
"winmm",
19+
]
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
#
3+
# This script is used to "import" the application-services into mozilla-central/firefox-main and arrange
4+
# for a successful build.
5+
#
6+
# This script must be run with the current directory being a clean m-c/m-f/f-m/fml/ where you want patches applied.
7+
#
8+
# WARNING: This messes with git in the current directory.
9+
# It DOES NOT check it is being run in a clean environment or on the correct branch.
10+
11+
# While this script lives in app-services for convenience, it uses git to fetch app-services.
12+
# This script can be anywhere but it must be run with the correct cwd - see above.
13+
#
14+
# If this is successful, it will have created a number of git commits and should be able to build and run Fenix.
15+
set -ex
16+
17+
if [[ ! -d "$(pwd)/toolkit/components" ]]; then
18+
echo "ERROR: This script must be run from the root of mozilla-central/mozilla-firefox/firefox-main/whatever-we-are-calling-it"
19+
exit 1
20+
fi
21+
22+
# If this happens to be a jj repo things get strange
23+
export MOZ_AVOID_JJ_VCS=1
24+
25+
# existing patches against m-c
26+
# gradle
27+
moz-phab patch --apply-to=here --no-branch D245762
28+
#lint
29+
moz-phab patch --apply-to=here --no-branch D246875
30+
31+
# the import of app-services via a branch markh is maintaining while we work towards `main`
32+
git clone https://github.com/mozilla/application-services tmp-app-services
33+
cd tmp-app-services
34+
git co monorepo
35+
36+
# xxx - this show-ref confused me - why doesn't `HEAD` work in place of refs/heads/monorepo??
37+
commit=$(git show-ref refs/heads/monorepo | awk '{print $1}')
38+
39+
rm -rf .git .github
40+
rm CHANGELOG.md CODE_OF_CONDUCT.md LICENSE README.md COPYRIGHT version.txt
41+
rm Cargo.lock Cargo.toml clippy.toml
42+
rm gradlew gradlew.bat build.gradle gradle.properties
43+
rm -rf gradle
44+
rm proguard-rules-consumer-jna.pro
45+
rm install-nimbus-cli.sh
46+
rm rust-toolchain.toml
47+
rm -rf components/external
48+
rm -rf docs/shared
49+
# need a story for these generated deps - bug 1963617
50+
rm DEPENDENCIES.md megazords/full/android/dependency-licenses.xml megazords/full/DEPENDENCIES.md megazords/ios-rust/DEPENDENCIES.md megazords/ios-rust/focus/DEPENDENCIES.md
51+
# No Taskcluster for now, testing etc should come for free (or need tweaks to add the new components etc?)
52+
rm -rf taskcluster/app_services_taskgraph taskcluster
53+
54+
cd ..
55+
56+
mkdir -p services/app-services
57+
cp -r tmp-app-services/* services/app-services
58+
cp -r tmp-app-services/.buildconfig-android.yml services/app-services
59+
60+
rm -rf tmp-app-services
61+
62+
git add services/app-services
63+
git commit -m "Import application-services commit $commit"
64+
65+
# We've committed an app-services unmodified apart from removal of things we don't need.
66+
# Update Cargo.toml and re-vendor.
67+
sed -i '' \
68+
-e 's|context_id = { git = .*$|context_id = { path = "services/app-services/components/context_id" }|' \
69+
-e 's|filter_adult = { git = .*$|filter_adult = { path = "services/app-services/components/filter_adult" }|' \
70+
-e 's|interrupt-support = { git = .*$|interrupt-support = { path = "services/app-services/components/support/interrupt" }|' \
71+
-e 's|relevancy = { git = .*$|relevancy = { path = "services/app-services/components/relevancy" }|' \
72+
-e 's|search = { git = .*$|search = { path = "services/app-services/components/search" }|' \
73+
-e 's|sql-support = { git = .*$|sql-support = { path = "services/app-services/components/support/sql" }|' \
74+
-e 's|suggest = { git = .*$|suggest = { path = "services/app-services/components/suggest" }|' \
75+
-e 's|sync15 = { git = .*$|sync15 = { path = "services/app-services/components/sync15" }|' \
76+
-e 's|tabs = { git = .*$|tabs = { path = "services/app-services/components/tabs" }|' \
77+
-e 's|viaduct = { git = .*$|viaduct = { path = "services/app-services/components/viaduct" }|' \
78+
-e 's|webext-storage = { git = .*$|webext-storage = { path = "services/app-services/components/webext-storage" }|' \
79+
Cargo.toml
80+
81+
./mach vendor rust
82+
# This will create a commit with Cargo.lock changing just for these crates, and many `third_party/rust` directories removed.
83+
git commit -a -m "Re-vendor application-services from its new in-tree home"
84+
85+
# apply the final "patch" in the stack, which we do by abusing sed.
86+
# This is mildly (hah!) fragile.
87+
88+
# [dependencies] is conveniently at the end of these toml files
89+
printf 'mozilla-central-workspace-hack = { version = "0.1", features = ["megazord"], optional = true }\n' >> services/app-services/megazords/full/Cargo.toml
90+
printf 'mozilla-central-workspace-hack = { version = "0.1", features = ["embedded-uniffi-bindgen"], optional = true }\n' >> services/app-services/tools/embedded-uniffi-bindgen/Cargo.toml
91+
# We need to update the crate-type for the megazord
92+
sed -i '' -e 's|crate-type = \["cdylib"\]|crate-type = \["staticlib"\]|' services/app-services/megazords/full/Cargo.toml
93+
# [features] is conveniently at the end of this toml
94+
printf 'megazord = []\nembedded-uniffi-bindgen = []\n' >> build/workspace-hack/Cargo.toml
95+
# and more hacks - sue me ;) In the short term these are more fragile in theory than practice.
96+
97+
# Add the 2 crates to the workspace which have binary targets
98+
sed -i '' \
99+
-e 's| "security/mls/mls_gk",| "security/mls/mls_gk",\
100+
"services/app-services/megazords/full",\
101+
"services/app-services/tools/embedded-uniffi-bindgen",|' \
102+
Cargo.toml
103+
104+
# exclude all the app-services crates.
105+
sed -i '' \
106+
-e 's| "intl/l10n/rust/l10nregistry-tests",| "intl/l10n/rust/l10nregistry-tests",\
107+
\
108+
# app-services excluded members, also to avoid dev dependencies.\
109+
"services/app-services/components/autofill",\
110+
"services/app-services/components/fxa-client",\
111+
"services/app-services/components/logins",\
112+
"services/app-services/components/nimbus",\
113+
"services/app-services/components/places",\
114+
"services/app-services/components/push",\
115+
"services/app-services/components/relevancy",\
116+
"services/app-services/components/remote_settings",\
117+
"services/app-services/components/search",\
118+
"services/app-services/components/suggest",\
119+
"services/app-services/components/support/guid",\
120+
"services/app-services/components/support/sql",\
121+
"services/app-services/components/sync15",\
122+
"services/app-services/components/tabs",\
123+
# app-services excluded members, for other reasons.\
124+
"services/app-services/megazords/ios-rust",|' \
125+
Cargo.toml
126+
127+
# Cargo.lock
128+
cargo update -p gkrust-shared
129+
git commit -a -m "Integrate app-services into the build system"
130+
131+
# XXX - Final vendor due to tracing-subscriber, hack for now
132+
./mach vendor rust --force --ignore-modified
133+
git commit -a -m "TODO - fix tracing"
134+
135+
echo "Done!"

0 commit comments

Comments
 (0)