From d7f0b286feda66aa4b91d28a52d843251d1c9dcd Mon Sep 17 00:00:00 2001 From: Ben Dean-Kawamura Date: Wed, 3 Aug 2022 18:59:38 +0000 Subject: [PATCH] Bug 1766045 - Fixes to make the hybrid builds work r=markh,teshaq This is a repsonse to the build errors I noticed with build-macosx64-hybrid/plain, build-win64-hybrid/plain, and build-linux64-hybrid/plain. I'm not exactly sure why those build had errors but others didn't, but my guess is that it was a combination of: - A clang++ producing different warnings/errors. - The uniffied builds being arranged slightly differently, which surfaced errors based on missing include statements. Differential Revision: https://phabricator.services.mozilla.com/D153414 --- .../uniffi-bindgen-gecko-js/src/render/cpp.rs | 6 ++++++ .../src/templates/UniFFIScaffolding.cpp | 8 ++++++++ toolkit/components/uniffi-js/ScaffoldingCall.h | 18 +++++++++--------- .../uniffi-js/UniFFIGeneratedScaffolding.cpp | 15 ++------------- toolkit/components/uniffi-js/UniFFIPointer.h | 2 ++ .../components/uniffi-js/UniFFIScaffolding.cpp | 1 + .../components/uniffi-js/UniFFIScaffolding.h | 2 ++ 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs index b99fcf344f65..ab9e42cb8487 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs @@ -25,6 +25,12 @@ pub struct CPPScaffoldingTemplate<'a> { pub object_ids: &'a ObjectIds<'a>, } +impl<'a> CPPScaffoldingTemplate<'a> { + fn has_any_objects(&self) -> bool { + self.ci_list.iter().any(|ci| ci.object_definitions().len() > 0) + } +} + // Define extension traits with methods used in our template code #[ext(name=ComponentInterfaceCppExt)] diff --git a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp index 862564c261bb..cd95029d2c7d 100644 --- a/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp +++ b/toolkit/components/uniffi-bindgen-gecko-js/src/templates/UniFFIScaffolding.cpp @@ -68,6 +68,7 @@ bool {{ prefix }}CallSync(const GlobalObject& aGlobal, uint64_t aId, const Seque } Maybe> {{ prefix }}ReadPointer(const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { + {%- if self.has_any_objects() %} const UniFFIPointerType* type; switch (aId) { {%- for ci in ci_list %} @@ -82,9 +83,13 @@ Maybe> {{ prefix }}ReadPointer(const GlobalObjec return Nothing(); } return Some(UniFFIPointer::Read(aArrayBuff, aPosition, type, aError)); + {%- else %} + return Nothing(); + {%- endif %} } bool {{ prefix }}WritePointer(const GlobalObject& aGlobal, uint64_t aId, const UniFFIPointer& aPtr, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { + {%- if self.has_any_objects() %} const UniFFIPointerType* type; switch (aId) { {%- for ci in ci_list %} @@ -100,6 +105,9 @@ bool {{ prefix }}WritePointer(const GlobalObject& aGlobal, uint64_t aId, const U } aPtr.Write(aArrayBuff, aPosition, type, aError); return true; + {%- else %} + return false; + {%- endif %} } } // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-js/ScaffoldingCall.h b/toolkit/components/uniffi-js/ScaffoldingCall.h index bd6efd8aad63..c4da399fbc52 100644 --- a/toolkit/components/uniffi-js/ScaffoldingCall.h +++ b/toolkit/components/uniffi-js/ScaffoldingCall.h @@ -134,8 +134,8 @@ class ScaffoldingCallHandler { using RustArgs = std::tuple; using IntermediateArgs = std::tuple; - using RustCallResult = RustCallResult; - using TaskPromiseType = MozPromise; + using CallResult = RustCallResult; + using TaskPromiseType = MozPromise; template using NthArgConverter = @@ -180,8 +180,8 @@ class ScaffoldingCallHandler { // Call the scaffolding function // // For async calls this should be called in the worker thread - static RustCallResult CallScaffoldingFunc(ScaffoldingFunc aFunc, - IntermediateArgs&& aArgs) { + static CallResult CallScaffoldingFunc(ScaffoldingFunc aFunc, + IntermediateArgs&& aArgs) { return CallScaffoldingFuncHelper( aFunc, std::move(aArgs), std::index_sequence_for()); } @@ -189,10 +189,10 @@ class ScaffoldingCallHandler { // Helper function for CallScaffoldingFunc that uses c++ magic to help with // iteration template - static RustCallResult CallScaffoldingFuncHelper( - ScaffoldingFunc aFunc, IntermediateArgs&& aArgs, - std::index_sequence seq) { - RustCallResult result; + static CallResult CallScaffoldingFuncHelper(ScaffoldingFunc aFunc, + IntermediateArgs&& aArgs, + std::index_sequence seq) { + CallResult result; auto makeCall = [&]() mutable { return aFunc( @@ -211,7 +211,7 @@ class ScaffoldingCallHandler { // // This should be called on the main thread static void ReturnResult( - JSContext* aContext, RustCallResult& aCallResult, + JSContext* aContext, CallResult& aCallResult, dom::RootedDictionary& aReturnValue, const nsLiteralCString& aFuncName) { switch (aCallResult.mCallStatus.code) { diff --git a/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp b/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp index ca19440a8570..ccbaef273345 100644 --- a/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp +++ b/toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp @@ -36,22 +36,11 @@ bool UniFFICallSync(const GlobalObject& aGlobal, uint64_t aId, const Sequence> UniFFIReadPointer(const GlobalObject& aGlobal, uint64_t aId, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - default: - return Nothing(); - } - return Some(UniFFIPointer::Read(aArrayBuff, aPosition, type, aError)); + return Nothing(); } bool UniFFIWritePointer(const GlobalObject& aGlobal, uint64_t aId, const UniFFIPointer& aPtr, const ArrayBuffer& aArrayBuff, long aPosition, ErrorResult& aError) { - const UniFFIPointerType* type; - switch (aId) { - default: - return false; - } - aPtr.Write(aArrayBuff, aPosition, type, aError); - return true; + return false; } } // namespace mozilla::uniffi diff --git a/toolkit/components/uniffi-js/UniFFIPointer.h b/toolkit/components/uniffi-js/UniFFIPointer.h index 9a824d81ede4..aba06b756d10 100644 --- a/toolkit/components/uniffi-js/UniFFIPointer.h +++ b/toolkit/components/uniffi-js/UniFFIPointer.h @@ -10,6 +10,8 @@ #include "nsISupports.h" #include "nsWrapperCache.h" #include "nsString.h" +#include "mozilla/ErrorResult.h" +#include "mozilla/dom/TypedArray.h" #include "mozilla/dom/UniFFIPointerType.h" namespace mozilla::dom { diff --git a/toolkit/components/uniffi-js/UniFFIScaffolding.cpp b/toolkit/components/uniffi-js/UniFFIScaffolding.cpp index 6be1693faf7e..3836323061d9 100644 --- a/toolkit/components/uniffi-js/UniFFIScaffolding.cpp +++ b/toolkit/components/uniffi-js/UniFFIScaffolding.cpp @@ -16,6 +16,7 @@ // purpose is to check if MOZ_UNIFFI_FIXTURES is set and only try calling the // scaffolding code if it is. +using mozilla::dom::ArrayBuffer; using mozilla::dom::GlobalObject; using mozilla::dom::Promise; using mozilla::dom::RootedDictionary; diff --git a/toolkit/components/uniffi-js/UniFFIScaffolding.h b/toolkit/components/uniffi-js/UniFFIScaffolding.h index 7b0270cd77a2..9aee71252a56 100644 --- a/toolkit/components/uniffi-js/UniFFIScaffolding.h +++ b/toolkit/components/uniffi-js/UniFFIScaffolding.h @@ -7,7 +7,9 @@ #ifndef mozilla_dom_UniFFI_h #define mozilla_dom_UniFFI_h +#include "mozilla/ErrorResult.h" #include "mozilla/dom/RootedDictionary.h" +#include "mozilla/dom/TypedArray.h" #include "mozilla/dom/UniFFIBinding.h" namespace mozilla::dom {