Skip to content
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
10 changes: 5 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cc_library(
"//implementation:array",
"//implementation:array_type_conversion",
"//implementation:array_view",
"//implementation:bind_lang_imports",
"//implementation:class",
"//implementation:class_loader",
"//implementation:configuration",
Expand All @@ -62,7 +63,6 @@ cc_library(
"//implementation:global_object",
"//implementation:global_string",
"//implementation:id",
"//implementation:id_type",
"//implementation:jni_type",
"//implementation:jvm",
"//implementation:jvm_ref",
Expand All @@ -74,13 +74,11 @@ cc_library(
"//implementation:local_object",
"//implementation:local_string",
"//implementation:method",
"//implementation:no_idx",
"//implementation:params",
"//implementation:promotion_mechanics",
"//implementation:promotion_mechanics_tags",
"//implementation:proxy_convenience_aliases",
"//implementation:proxy_temporary",
"//implementation:ref_base",
"//implementation:return",
"//implementation:selector_static_info",
"//implementation:self",
Expand Down Expand Up @@ -169,13 +167,14 @@ cc_library(
genrule(
name = "gen_jni_bind_release",
outs = ["jni_bind_release.h"],
cmd = './$(location build_jni_bind_release.sh) $(location jni_bind_release_input) jni_wrapper $(locations :jni_bind_decorative_text) | sed "s/__JNI_BIND_VERSION__/`cat $(locations JNI_BIND_VERSION.inc)`/" >$@',
cmd = './$(execpath build_jni_bind_release.sh) $(execpath jni_bind_release_input) jni_wrapper $(execpaths :jni_bind_decorative_text) | sed "s/__JNI_BIND_VERSION__/`cat $(execpaths JNI_BIND_VERSION.inc)`/" >$@',
tools = [
":JNI_BIND_VERSION.inc",
":build_jni_bind_release.sh",
":headers_for_export",
":jni_bind_decorative_text",
":jni_bind_release_input",
"//bind_lang:headers_for_export",
"//bind_lang/metaprogramming:headers_for_export",
"//class_defs:headers_for_export",
"//class_defs/android:headers_for_export",
Expand All @@ -193,13 +192,14 @@ genrule(
genrule(
name = "gen_jni_bind_release_for_testing",
outs = ["jni_bind_release_for_testing.h"],
cmd = './$(location build_jni_bind_release.sh) $(location jni_bind_release_input) jni_wrapper $(locations :jni_bind_decorative_text) | sed "s/__JNI_BIND_VERSION__/`cat $(locations JNI_BIND_VERSION.inc)`/" >$@',
cmd = './$(execpath build_jni_bind_release.sh) $(execpath jni_bind_release_input) jni_wrapper $(execpaths :jni_bind_decorative_text) | sed "s/__JNI_BIND_VERSION__/`cat $(execpaths JNI_BIND_VERSION.inc)`/" >$@',
tools = [
":JNI_BIND_VERSION.inc",
":build_jni_bind_release.sh",
":headers_for_export",
":jni_bind_decorative_text",
":jni_bind_release_input",
"//bind_lang:headers_for_export",
"//bind_lang/metaprogramming:headers_for_export",
"//class_defs:headers_for_export",
"//class_defs/android:headers_for_export",
Expand Down
35 changes: 35 additions & 0 deletions bind_lang/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")

# `bind_lang` is the language-agnostic core of the binding libraries (JNI Bind,
# Proto Bind). Targets here must never depend on `//third_party/jni_wrapper/implementation`
# (JNI Bind) or any other language-specific package.
package(
default_visibility = ["//:__subpackages__"],
)

licenses(["notice"])

filegroup(
name = "headers_for_export",
srcs = glob(["*.h"]),
)

cc_library(
name = "id_type",
hdrs = ["id_type.h"],
)

cc_library(
name = "no_idx",
hdrs = ["no_idx.h"],
)

cc_library(
name = "lifecycle",
hdrs = ["lifecycle.h"],
)

cc_library(
name = "ref_base",
hdrs = ["ref_base.h"],
)
12 changes: 5 additions & 7 deletions implementation/id_type.h → bind_lang/id_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
* limitations under the License.
*/

#ifndef JNI_BIND_IMPLEMENTATION_ID_TYPE_H_
#define JNI_BIND_IMPLEMENTATION_ID_TYPE_H_
#ifndef JNI_BIND_BIND_LANG_ID_TYPE_H_
#define JNI_BIND_BIND_LANG_ID_TYPE_H_

// IWYU pragma: private, include "third_party/jni_wrapper/jni_bind.h"

namespace jni {
namespace bind_lang {

enum class IdType {
CLASS,
Expand All @@ -33,6 +31,6 @@ enum class IdType {
FIELD,
};

} // namespace jni
} // namespace bind_lang

#endif // JNI_BIND_IMPLEMENTATION_ID_TYPE_H_
#endif // JNI_BIND_BIND_LANG_ID_TYPE_H_
43 changes: 43 additions & 0 deletions bind_lang/lifecycle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef JNI_BIND_BIND_LANG_LIFECYCLE_H_
#define JNI_BIND_BIND_LANG_LIFECYCLE_H_

namespace bind_lang {

// Ownership model of a runtime handle (e.g. a JNI `jobject` or a
// `google::protobuf::Message*`).
enum class LifecycleType {
LOCAL,
GLOBAL,
// WEAK, // not implemented yet.
};

// Customization point for creating, duplicating, promoting, and releasing
// handles of type `Span` under a given `LifecycleType`.
//
// Each binding language specializes this for its own handle types, providing
// whichever of the following static members it supports:
// `Construct(...)`, `NewReference(Span)`, `Promote(Span)`, `Delete(Span)`.
//
// Specializations must be declared in `namespace bind_lang`.
template <typename Span, LifecycleType lifecycle_type>
struct LifecycleHelper;

} // namespace bind_lang

#endif // JNI_BIND_BIND_LANG_LIFECYCLE_H_
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ cc_library(
],
)

# Currently not running because of a bug in gcc C++20 on Github's Bazel.
# Currently not running because of a bug in gcc C++20 on GitHub's Bazel.
#cc_test(
# name = "queryable_map_test",
# srcs = ["queryable_map_test.cc"],
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/contains_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static_assert(!TupContains_v<int, std::tuple<float>>);
static_assert(!TupContains_v<int, std::tuple<float, double>>);
static_assert(!TupContains_v<int, std::tuple<float, double, A>>);

// Simple paramater packs.
// Simple parameter packs.
static_assert(Contains_v<void, void>);
static_assert(Contains_v<void, int, void>);
static_assert(Contains_v<void, void, int>);
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/find_idx_of_val.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct FindIdxOfVal {
}
};

// Done once in a seperate struct for improved compilation time.
// Done once in a separate struct for improved compilation time.
template <typename... Ts>
struct StaticAssertWrapper {
static_assert(AllUnique_v<Ts...>,
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/invocable_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace bind_lang::metaprogramming {
// directly pass a const auto&, however, this prevents accessing subobjects.
//
// The motivation for using inheritance as opposed to a simple member is that
// the the const char cannot be propagated without losing its constexpr-ness,
// the const char cannot be propagated without losing its constexpr-ness,
// and so the clang extension can no longer restrict function candidates.
template <typename CrtpBase, const auto& tup_container_v,
typename TupContainerT, typename MemberT, MemberT nameable_member>
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/invocable_map_20.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace bind_lang::metaprogramming {
// |nameable_member| is pointer to member of the nameable type.
//
// The motivation for using inheritance as opposed to a simple member is that
// the the const char cannot be propagated without losing its constexpr-ness,
// the const char cannot be propagated without losing its constexpr-ness,
// and so the clang extension can no longer restrict function candidates.
template <typename CrtpBase, const auto& tup_container_v,
typename TupContainerT, typename MemberT, MemberT nameable_member>
Expand Down
3 changes: 2 additions & 1 deletion bind_lang/metaprogramming/modified_max.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <limits>

namespace bind_lang::metaprogramming {
Expand All @@ -33,7 +34,7 @@ constexpr std::size_t kNegativeOne = std::numeric_limits<std::size_t>::max();
// kNegativeOne if all elements are kNegativeOne.
constexpr std::size_t ModifiedMax(
std::initializer_list<std::size_t> initializer_lister) {
if (initializer_lister.size() == 0) {
if (std::empty(initializer_lister)) {
return kNegativeOne;
}

Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/queryable_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class QueryableMapBase {};
// directly pass a const auto&, however, this prevents accessing subobjects.
//
// The motivation for using inheritance as opposed to a simple member is that
// the the const char cannot be propagated without losing its constexpr-ness,
// the const char cannot be propagated without losing its constexpr-ness,
// and so the clang extension can no longer restrict function candidates.
template <typename CrtpBase, const auto& tup_container_v,
std::size_t container_size, typename TupContainerT, typename MemberT,
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/queryable_map_20.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace bind_lang::metaprogramming {
// |nameable_member| is pointer to member of the nameable type.
//
// The motivation for using inheritance as opposed to a simple member is that
// the the const char cannot be propagated without losing its constexpr-ness,
// the const char cannot be propagated without losing its constexpr-ness,
// and so the clang extension can no longer restrict function candidates.
template <typename CrtpBase, const auto& tup_container_v,
typename TupContainerT, typename MemberT, MemberT nameable_member>
Expand Down
2 changes: 1 addition & 1 deletion bind_lang/metaprogramming/vals_equal.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace bind_lang::metaprogramming {

// Performs a deep equality comparison of T, but is leniant about containers.
// Performs a deep equality comparison of T, but is lenient about containers.
// Returns true iff types are equal or both types are containers and their
// non-type template parameters are equal.
template <typename T>
Expand Down
14 changes: 6 additions & 8 deletions implementation/no_idx.h → bind_lang/no_idx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
* limitations under the License.
*/

#ifndef JNI_BIND_IMPLEMENTATION_NO_IDX_H_
#define JNI_BIND_IMPLEMENTATION_NO_IDX_H_

// IWYU pragma: private, include "third_party/jni_wrapper/jni_bind.h"
#ifndef JNI_BIND_BIND_LANG_NO_IDX_H_
#define JNI_BIND_BIND_LANG_NO_IDX_H_

#include <cstddef>
#include <limits>

namespace jni {
namespace bind_lang {

static constexpr std::size_t kNoIdx{std::numeric_limits<std::size_t>::max()};
inline constexpr std::size_t kNoIdx = std::numeric_limits<std::size_t>::max();

} // namespace jni
} // namespace bind_lang

#endif // JNI_BIND_IMPLEMENTATION_NO_IDX_H_
#endif // JNI_BIND_BIND_LANG_NO_IDX_H_
30 changes: 8 additions & 22 deletions implementation/ref_base.h → bind_lang/ref_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@
* limitations under the License.
*/

#ifndef JNI_BIND_REF_BASE_H_
#define JNI_BIND_REF_BASE_H_
#ifndef JNI_BIND_BIND_LANG_REF_BASE_H_
#define JNI_BIND_BIND_LANG_REF_BASE_H_

// IWYU pragma: private, include "third_party/jni_wrapper/jni_bind.h"

#include <type_traits>

#include "implementation/jni_helper/lifecycle.h"

namespace jni {
namespace bind_lang {

struct RefBaseBase {};

Expand All @@ -33,40 +27,32 @@ struct RefBaseBase {};
template <typename StorageType>
class RefBase : public RefBaseBase {
public:
template <typename Base, LifecycleType lifecycleType, typename JniT,
typename ViableSpan>
friend struct EntryBase;

RefBase(StorageType object) : object_ref_(object) {}

RefBase(const RefBase& rhs) = delete;

RefBase(RefBase&& rhs) {
object_ref_ = rhs.object_ref_;
rhs.object_ref_ = nullptr;
rhs.object_ref_ = StorageType{};
}

template <typename T,
typename = std::enable_if_t<std::is_same_v<T, StorageType>>>
RefBase(RefBase<T>&& rhs) : object_ref_(rhs.Release()) {}

// Releases ownership of the underlying object, further use is undefined.
StorageType Release() {
StorageType return_value = object_ref_;
object_ref_ = nullptr;
object_ref_ = StorageType{};

return return_value;
}
explicit operator StorageType() const { return object_ref_; }

protected:
StorageType object_ref_ = nullptr;
StorageType object_ref_ = StorageType{};
};

//==============================================================================
template <typename T>
using RefBaseT_t = typename T::RefBaseT;

} // namespace jni
} // namespace bind_lang

#endif // JNI_BIND_REF_BASE_H_
#endif // JNI_BIND_BIND_LANG_REF_BASE_H_
Loading
Loading