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
56 changes: 56 additions & 0 deletions megazords/fenix-dylib/megazord_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* -*- 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_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_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 @@ -26,6 +27,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",
]