diff --git a/megazords/fenix-dylib/megazord_stub.c b/megazords/fenix-dylib/megazord_stub.c new file mode 100644 index 0000000000..7b8ddba8ad --- /dev/null +++ b/megazords/fenix-dylib/megazord_stub.c @@ -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(); +} diff --git a/megazords/fenix-dylib/moz.build b/megazords/fenix-dylib/moz.build new file mode 100644 index 0000000000..a17a1db367 --- /dev/null +++ b/megazords/fenix-dylib/moz.build @@ -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", + ] diff --git a/megazords/full/moz.build b/megazords/full/moz.build new file mode 100644 index 0000000000..d4ebe0b834 --- /dev/null +++ b/megazords/full/moz.build @@ -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", +] diff --git a/megazords/full/src/lib.rs b/megazords/full/src/lib.rs index 4b6ba44999..43eaed62f5 100644 --- a/megazords/full/src/lib.rs +++ b/megazords/full/src/lib.rs @@ -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; @@ -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; diff --git a/megazords/full/stub.cpp b/megazords/full/stub.cpp new file mode 100644 index 0000000000..bd20c15c4f --- /dev/null +++ b/megazords/full/stub.cpp @@ -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. diff --git a/moz.build b/moz.build new file mode 100644 index 0000000000..cdc5e78c85 --- /dev/null +++ b/moz.build @@ -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", + ] diff --git a/tools/embedded-uniffi-bindgen/Cargo.toml b/tools/embedded-uniffi-bindgen/Cargo.toml index 8d008666fb..68a0c9bbea 100644 --- a/tools/embedded-uniffi-bindgen/Cargo.toml +++ b/tools/embedded-uniffi-bindgen/Cargo.toml @@ -5,5 +5,9 @@ authors = ["The Firefox Sync Developers "] 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"] } diff --git a/tools/embedded-uniffi-bindgen/moz.build b/tools/embedded-uniffi-bindgen/moz.build new file mode 100644 index 0000000000..24201609d9 --- /dev/null +++ b/tools/embedded-uniffi-bindgen/moz.build @@ -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", + ]