Skip to content

Commit

Permalink
Bug 1766045 - Fixes to make the hybrid builds work r=markh,teshaq
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bendk committed Aug 3, 2022
1 parent f4102dd commit d7f0b28
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
6 changes: 6 additions & 0 deletions toolkit/components/uniffi-bindgen-gecko-js/src/render/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ bool {{ prefix }}CallSync(const GlobalObject& aGlobal, uint64_t aId, const Seque
}

Maybe<already_AddRefed<UniFFIPointer>> {{ 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 %}
Expand All @@ -82,9 +83,13 @@ Maybe<already_AddRefed<UniFFIPointer>> {{ 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 %}
Expand All @@ -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
18 changes: 9 additions & 9 deletions toolkit/components/uniffi-js/ScaffoldingCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class ScaffoldingCallHandler {
using RustArgs = std::tuple<typename ArgConverters::RustType...>;
using IntermediateArgs =
std::tuple<typename ArgConverters::IntermediateType...>;
using RustCallResult = RustCallResult<typename ReturnConverter::RustType>;
using TaskPromiseType = MozPromise<RustCallResult, nsresult, true>;
using CallResult = RustCallResult<typename ReturnConverter::RustType>;
using TaskPromiseType = MozPromise<CallResult, nsresult, true>;

template <size_t I>
using NthArgConverter =
Expand Down Expand Up @@ -180,19 +180,19 @@ 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<ArgConverters...>());
}

// Helper function for CallScaffoldingFunc that uses c++ magic to help with
// iteration
template <size_t... Is>
static RustCallResult CallScaffoldingFuncHelper(
ScaffoldingFunc aFunc, IntermediateArgs&& aArgs,
std::index_sequence<Is...> seq) {
RustCallResult result;
static CallResult CallScaffoldingFuncHelper(ScaffoldingFunc aFunc,
IntermediateArgs&& aArgs,
std::index_sequence<Is...> seq) {
CallResult result;

auto makeCall = [&]() mutable {
return aFunc(
Expand All @@ -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<dom::UniFFIScaffoldingCallResult>& aReturnValue,
const nsLiteralCString& aFuncName) {
switch (aCallResult.mCallStatus.code) {
Expand Down
15 changes: 2 additions & 13 deletions toolkit/components/uniffi-js/UniFFIGeneratedScaffolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,11 @@ bool UniFFICallSync(const GlobalObject& aGlobal, uint64_t aId, const Sequence<Sc
}

Maybe<already_AddRefed<UniFFIPointer>> 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
2 changes: 2 additions & 0 deletions toolkit/components/uniffi-js/UniFFIPointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions toolkit/components/uniffi-js/UniFFIScaffolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions toolkit/components/uniffi-js/UniFFIScaffolding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d7f0b28

Please sign in to comment.