Skip to content

Add build tooling so we can work in mozilla-central. #6692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions megazords/fenix-dylib/megazord_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

#include "mozilla/Types.h"

// This seems sad?
// If we could get a stub .rs we could use `tabs::uniffi_reexport_scaffolding!();` etc,
// but here we are.
// To get the symbols from our static lib we need to refer to a symbol from each crate within it.
// This is an arbitrary choice - any symbol will do, but we chose these because every uniffi crate has it.
extern int MOZ_EXPORT ffi_autofill_uniffi_contract_version();
extern int MOZ_EXPORT ffi_crashtest_uniffi_contract_version();
extern int MOZ_EXPORT ffi_fxa_client_uniffi_contract_version();
extern int MOZ_EXPORT ffi_init_rust_components_uniffi_contract_version();
extern int MOZ_EXPORT ffi_logins_uniffi_contract_version();
extern int MOZ_EXPORT ffi_merino_uniffi_contract_version();
extern int MOZ_EXPORT ffi_nimbus_uniffi_contract_version();
extern int MOZ_EXPORT ffi_places_uniffi_contract_version();
extern int MOZ_EXPORT ffi_push_uniffi_contract_version();
extern int MOZ_EXPORT ffi_relay_uniffi_contract_version();
extern int MOZ_EXPORT ffi_remote_settings_uniffi_contract_version();
extern int MOZ_EXPORT ffi_rust_log_forwarder_uniffi_contract_version();
extern int MOZ_EXPORT ffi_search_uniffi_contract_version();
extern int MOZ_EXPORT ffi_suggest_uniffi_contract_version();
extern int MOZ_EXPORT ffi_sync15_uniffi_contract_version();
extern int MOZ_EXPORT ffi_sync_manager_uniffi_contract_version();
extern int MOZ_EXPORT ffi_tabs_uniffi_contract_version();

// far out, this is crazy - without this, only the search _NAMESPACE meta comes in,
// meaning uniffi ends up generating a completely empty kotlin module for search.
// Looking at `nm obj-dir/.../libsearch-*.rlib` you can see many symbols
// are in a different .o - this symbol is one taken randomly from the .o with
// the missing symbols, and they all happily come in.
// W T A F.
extern int MOZ_EXPORT uniffi_search_checksum_constructor_searchengineselector_new();

void _local_megazord_dummy_symbol() {
ffi_autofill_uniffi_contract_version();
ffi_crashtest_uniffi_contract_version();
ffi_fxa_client_uniffi_contract_version();
ffi_init_rust_components_uniffi_contract_version();
ffi_logins_uniffi_contract_version();
ffi_merino_uniffi_contract_version();
ffi_nimbus_uniffi_contract_version();
ffi_places_uniffi_contract_version();
ffi_push_uniffi_contract_version();
ffi_relay_uniffi_contract_version();
ffi_remote_settings_uniffi_contract_version();
ffi_rust_log_forwarder_uniffi_contract_version();
ffi_search_uniffi_contract_version();
ffi_suggest_uniffi_contract_version();
ffi_sync15_uniffi_contract_version();
ffi_sync_manager_uniffi_contract_version();
ffi_tabs_uniffi_contract_version();
uniffi_search_checksum_constructor_searchengineselector_new();
}
35 changes: 35 additions & 0 deletions megazords/fenix-dylib/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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/.

# There are 2 parts to our megazord - a staticlib in megazords/full, then this
# build file to create the final dyib .so
# See the comments in megazords/full/moz.build.

UNIFIED_SOURCES += [
"megazord_stub.c",
]

# This name confusion is a reflection of the 2 megazord parts. It should be
# fixed after we land in m-c.
SharedLibrary("megazord-so")
SHARED_LIBRARY_NAME = "megazord"

USE_LIBS += ["megazord", "mozpkix", "nspr"]

# copy-pasta from other moz.build files.
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
OS_LIBS += ["-framework CoreFoundation"]
elif CONFIG["OS_TARGET"] == "WINNT":
OS_LIBS += [
"advapi32",
"bcrypt",
"mswsock",
"ntdll",
"shell32",
"user32",
"userenv",
"wsock32",
"ws2_32",
"winmm",
]
22 changes: 22 additions & 0 deletions megazords/full/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.

# Note that this crate, when used in app-services, directly creates the cdylib.
# However, in moz-central it builds a staticlib. A new target in `../fenix-dylib`
# takes this as a dep and creates the final cdylib.
USE_LIBS += ["nss"]

UNIFIED_SOURCES += [
"stub.cpp",
]

# This is the name of the .a file created.
RustLibrary("megazord")

# XXX - this doesn't really work - the tests fail due to missing `nss3`?
RUST_TESTS = [
"megazord",
]
3 changes: 3 additions & 0 deletions megazords/full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::ffi::CString;
use std::os::raw::c_char;

// NOTE if you add or remove crates below here, please make a corresponding change in ../fenix-dylib/megazord_stub.c
pub use autofill;
pub use crashtest;
pub use error_support;
Expand All @@ -27,6 +28,8 @@ pub use sync_manager;
pub use tabs;
pub use tracing_support;
pub use viaduct;
// NOTE if you add or remove crates above here, please make a corresponding change in ../fenix-dylib/megazord_stub.c

// TODO: Uncomment this code when webext-storage component is integrated in android
// pub use webext_storage;

Expand Down
8 changes: 8 additions & 0 deletions megazords/full/stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */

// This is an intentionally empty file. It is necessary for the build system to
// successfully convert a static rust library into a dynamic library on
// Windows.
34 changes: 34 additions & 0 deletions moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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/.

# Note that this builds the cdylib for our megazord. See the comments
# in megazords/full/moz.build.

UNIFIED_SOURCES += [
"megazord_stub.c",
]

# This name confusion is a reflection of some of the above. It should be
# fixed, but may be easier/better to fix once in m-c.
SharedLibrary("megazord-so")
SHARED_LIBRARY_NAME = "megazord"

USE_LIBS += ["megazord", "mozpkix", "nspr"]

# copy-pasta from other moz.build files, are these the correct checks?
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
OS_LIBS += ["-framework CoreFoundation"]
elif CONFIG["OS_TARGET"] == "WINNT":
OS_LIBS += [
"advapi32",
"bcrypt",
"mswsock",
"ntdll",
"shell32",
"user32",
"userenv",
"wsock32",
"ws2_32",
"winmm",
]
4 changes: 4 additions & 0 deletions tools/embedded-uniffi-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ authors = ["The Firefox Sync Developers <[email protected]>"]
edition = "2021"
license = "MPL-2.0"

# A bin target needed when used in m-c.
[[bin]]
name = "embedded-uniffi-bindgen"

[dependencies]
uniffi = { version = "0.29.0", features = ["cli"] }
19 changes: 19 additions & 0 deletions tools/embedded-uniffi-bindgen/moz.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.

HOST_RUST_PROGRAMS = ["embedded-uniffi-bindgen"]

# copy-pasta from other moz.build file.
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
OS_LIBS += ["-framework CoreFoundation"]
elif CONFIG["OS_TARGET"] == "WINNT":
OS_LIBS += [
"advapi32",
"wsock32",
"ws2_32",
"mswsock",
"winmm",
]
138 changes: 138 additions & 0 deletions tools/import-app-services-to-central.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/bash
#
# This script is used to "import" the application-services into mozilla-central/firefox-main and arrange
# for a successful build.
#
# This script must be run with the current directory being a clean m-c/m-f/f-m/fml/ where you want patches applied.
#
# WARNING: This messes with git in the current directory.
# It DOES NOT check it is being run in a clean environment or on the correct branch.

# While this script lives in app-services for convenience, it uses git to fetch app-services.
# This script can be anywhere but it must be run with the correct cwd - see above.
#
# If this is successful, it will have created a number of git commits and should be able to build and run Fenix.
set -ex

if [[ ! -d "$(pwd)/toolkit/components" ]]; then
echo "ERROR: This script must be run from the root of mozilla-central/mozilla-firefox/firefox-main/whatever-we-are-calling-it"
exit 1
fi

# If this happens to be a jj repo things get strange
export MOZ_AVOID_JJ_VCS=1

# existing patches against m-c
# gradle
moz-phab patch --apply-to=here --no-branch D245762
#lint
moz-phab patch --apply-to=here --no-branch D246875

# the import of app-services via a branch markh is maintaining while we work towards `main`
git clone https://github.com/mozilla/application-services tmp-app-services
cd tmp-app-services
git co monorepo

# xxx - this show-ref confused me - why doesn't `HEAD` work in place of refs/heads/monorepo??
commit=$(git show-ref refs/heads/monorepo | awk '{print $1}')

rm -rf .git .github
rm CHANGELOG.md CODE_OF_CONDUCT.md LICENSE README.md COPYRIGHT version.txt
rm Cargo.lock Cargo.toml clippy.toml
rm gradlew gradlew.bat build.gradle gradle.properties
rm -rf gradle
rm proguard-rules-consumer-jna.pro
rm install-nimbus-cli.sh
rm rust-toolchain.toml
rm -rf components/external
rm -rf docs/shared
# need a story for these generated deps - bug 1963617
rm DEPENDENCIES.md megazords/full/android/dependency-licenses.xml megazords/full/DEPENDENCIES.md megazords/ios-rust/DEPENDENCIES.md megazords/ios-rust/focus/DEPENDENCIES.md

cd ..

mkdir -p services/app-services
cp -r tmp-app-services/* services/app-services
cp -r tmp-app-services/.buildconfig-android.yml services/app-services

rm -rf tmp-app-services

git add services/app-services
git commit -m "Import application-services commit $commit"

git mv services/app-services/taskcluster/app_services_taskgraph taskcluster
# (XXX - this tries to replace a few files which we don't want.)
#mv services/app-services/taskcluster/scripts/* taskcluster/scripts
git commit taskcluster services/app-services -m "Move various taskcluster files to the appropriate location in the moz-central"

# Update Cargo.toml and re-vendor
sed -i '' \
-e 's|context_id = { git = .*$|context_id = { path = "services/app-services/components/context_id" }|' \
-e 's|filter_adult = { git = .*$|filter_adult = { path = "services/app-services/components/filter_adult" }|' \
-e 's|interrupt-support = { git = .*$|interrupt-support = { path = "services/app-services/components/support/interrupt" }|' \
-e 's|relevancy = { git = .*$|relevancy = { path = "services/app-services/components/relevancy" }|' \
-e 's|search = { git = .*$|search = { path = "services/app-services/components/search" }|' \
-e 's|sql-support = { git = .*$|sql-support = { path = "services/app-services/components/support/sql" }|' \
-e 's|suggest = { git = .*$|suggest = { path = "services/app-services/components/suggest" }|' \
-e 's|sync15 = { git = .*$|sync15 = { path = "services/app-services/components/sync15" }|' \
-e 's|tabs = { git = .*$|tabs = { path = "services/app-services/components/tabs" }|' \
-e 's|viaduct = { git = .*$|viaduct = { path = "services/app-services/components/viaduct" }|' \
-e 's|webext-storage = { git = .*$|webext-storage = { path = "services/app-services/components/webext-storage" }|' \
Cargo.toml

./mach vendor rust
git commit -a -m "Re-vendor application-services from its new in-tree home"

# sed -i '' -e 's|org.gradle.configuration-cache=true|org.gradle.configuration-cache=false # disabled for app-services|' gradle.properties mobile/android/fenix/gradle.properties mobile/android/focus-android/gradle.properties
# git commit -a -m "Disable gradle cache"

# apply the final "patch" in the stack, which we do by abusing sed.
# This is mildly (hah!) fragile.

# [dependencies] is conveniently at the end of these toml files
printf 'mozilla-central-workspace-hack = { version = "0.1", features = ["megazord"], optional = true }\n' >> services/app-services/megazords/full/Cargo.toml
printf 'mozilla-central-workspace-hack = { version = "0.1", features = ["embedded-uniffi-bindgen"], optional = true }\n' >> services/app-services/tools/embedded-uniffi-bindgen/Cargo.toml
# We need to update the crate-type for the megazord
sed -i '' -e 's|crate-type = \["cdylib"\]|crate-type = \["staticlib"\]|' services/app-services/megazords/full/Cargo.toml
# [features] is conveniently at the end of this toml
printf 'megazord = []\n' >> build/workspace-hack/Cargo.toml
printf 'embedded-uniffi-bindgen = []\n' >> build/workspace-hack/Cargo.toml
# and more hacks - sue me ;) In the short term these are more fragile in theory than practice.

# Add the 2 crates to the workspace which have binary targets
sed -i '' \
-e 's| "security/mls/mls_gk",| "security/mls/mls_gk",\
"services/app-services/megazords/full",\
"services/app-services/tools/embedded-uniffi-bindgen",|' \
Cargo.toml

# exclude all the app-services crates.
sed -i '' \
-e 's| "intl/l10n/rust/l10nregistry-tests",| "intl/l10n/rust/l10nregistry-tests",\
\
# app-services excluded members, also to avoid dev dependencies.\
"services/app-services/components/autofill",\
"services/app-services/components/fxa-client",\
"services/app-services/components/logins",\
"services/app-services/components/nimbus",\
"services/app-services/components/places",\
"services/app-services/components/push",\
"services/app-services/components/relevancy",\
"services/app-services/components/remote_settings",\
"services/app-services/components/search",\
"services/app-services/components/suggest",\
"services/app-services/components/support/guid",\
"services/app-services/components/support/sql",\
"services/app-services/components/sync15",\
"services/app-services/components/tabs",|' \
Cargo.toml

# Cargo.lock
cargo update -p gkrust-shared
git commit -a -m "Integrate app-services into the build system"

# XXX - Final vendor due to tracing-subscriber, hack for now
./mach vendor rust --force --ignore-modified
git commit -a -m "TODO - fix tracing"

echo "Done! You probably want to create a git branch or whatever it is you do boo..."