Skip to content

Commit

Permalink
Merge branch 'google:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeblanc committed Apr 18, 2024
2 parents ec6a6a2 + 7106d86 commit 9ba1658
Show file tree
Hide file tree
Showing 29 changed files with 350 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
ts/node_modules
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# We cannot use "common" here because the "version" command doesn't support
# --deleted_packages. We need to specify it for both build and query instead.
build --deleted_packages=tests/ts/bazel_repository_test_dir
query --deleted_packages=tests/ts/bazel_repository_test_dir
build --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
query --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
26 changes: 26 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,32 @@ jobs:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

publish-maven-kotlin:
name: Publish Maven - Kotlin
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./kotlin
steps:
- uses: actions/checkout@v3

- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
cache: 'maven'
server-id: ossrh
server-username: OSSRH_USERNAME
server-password: OSSRH_PASSWORD
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var

- name: Publish Kotlin Library on Maven
run: ./gradlew publishAllPublicationsToSonatypeRepository
env:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}

13 changes: 4 additions & 9 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

licenses(["notice"])
Expand All @@ -8,13 +6,6 @@ package(
default_visibility = ["//visibility:public"],
)

npm_link_all_packages(name = "node_modules")

npm_link_package(
name = "node_modules/flatbuffers",
src = "//ts:flatbuffers",
)

exports_files([
"LICENSE",
"tsconfig.json",
Expand All @@ -37,9 +28,13 @@ config_setting(
filegroup(
name = "distribution",
srcs = [
".bazelignore",
".npmrc",
"BUILD.bazel",
"WORKSPACE",
"build_defs.bzl",
"package.json",
"pnpm-lock.yaml",
"typescript.bzl",
"//grpc/src/compiler:distribution",
"//reflection:distribution",
Expand Down
31 changes: 21 additions & 10 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ http_archive(
],
)

# Import our own version of skylib before other rule sets (e.g. rules_swift)
# has a chance to import an old version.
http_archive(
name = "bazel_skylib",
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "build_bazel_rules_apple",
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
Expand Down Expand Up @@ -101,7 +116,7 @@ load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock", "pnpm_repository")
load("@aspect_rules_js//npm:npm_import.bzl", "pnpm_repository")

pnpm_repository(name = "pnpm")

Expand Down Expand Up @@ -129,17 +144,13 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)

npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
# Set this to True when the lock file needs to be updated, commit the
# changes, then set to False again.
update_pnpm_lock = False,
verify_node_modules_ignored = "//:.bazelignore",
load("@com_github_google_flatbuffers//ts:repositories.bzl", "flatbuffers_npm")

flatbuffers_npm(
name = "flatbuffers_npm",
)

load("@npm//:repositories.bzl", "npm_repositories")
load("@flatbuffers_npm//:repositories.bzl", "npm_repositories")

npm_repositories()

Expand Down
12 changes: 7 additions & 5 deletions include/flatbuffers/flatbuffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) {
2 * sizeof(voffset_t); // Vtable size and Object Size.
size_t offset = fixed_fields + field_id * sizeof(voffset_t);
FLATBUFFERS_ASSERT(offset < std::numeric_limits<voffset_t>::max());
return static_cast<voffset_t>(offset);}
return static_cast<voffset_t>(offset);
}

template<typename T, typename Alloc = std::allocator<T>>
const T *data(const std::vector<T, Alloc> &v) {
Expand Down Expand Up @@ -241,7 +242,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
/// called.
uint8_t *ReleaseRaw(size_t &size, size_t &offset) {
Finished();
uint8_t* raw = buf_.release_raw(size, offset);
uint8_t *raw = buf_.release_raw(size, offset);
Clear();
return raw;
}
Expand Down Expand Up @@ -561,7 +562,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
return CreateString<OffsetT>(str.c_str(), str.length());
}

// clang-format off
// clang-format off
#ifdef FLATBUFFERS_HAS_STRING_VIEW
/// @brief Store a string in the buffer, which can contain any binary data.
/// @param[in] str A const string_view to copy in to the buffer.
Expand Down Expand Up @@ -743,7 +744,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
AssertScalarT<T>();
StartVector<T, OffsetT, LenT>(len);
if (len > 0) {
// clang-format off
// clang-format off
#if FLATBUFFERS_LITTLEENDIAN
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
#else
Expand Down Expand Up @@ -1470,7 +1471,8 @@ T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {

template<typename T>
const T *GetTemporaryPointer(const FlatBufferBuilder &fbb, Offset<T> offset) {
return GetMutableTemporaryPointer<T>(fbb, offset);
return reinterpret_cast<const T *>(fbb.GetCurrentBufferPointer() +
fbb.GetSize() - offset.o);
}

} // namespace flatbuffers
Expand Down
7 changes: 7 additions & 0 deletions kotlin/convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
`kotlin-dsl`
}

repositories {
gradlePluginPortal()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.`maven-publish`
import org.gradle.kotlin.dsl.signing
import java.util.*

plugins {
`maven-publish`
signing
}

// Stub secrets to let the project sync and build without the publication values set up
ext["signing.keyId"] = null
ext["signing.password"] = null
ext["signing.secretKeyRingFile"] = null
ext["ossrhUsername"] = null
ext["ossrhPassword"] = null

// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
secretPropsFile.reader().use {
Properties().apply {
load(it)
}
}.onEach { (name, value) ->
ext[name.toString()] = value
}
} else {
ext["signing.keyId"] = System.getenv("OSSRH_USERNAME")
ext["signing.password"] = System.getenv("OSSRH_PASSWORD")
ext["signing.secretKeyRingFile"] = System.getenv("INPUT_GPG_PRIVATE_KEY")
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
}

val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

fun getExtraString(name: String) = ext[name]?.toString()

publishing {
// Configure maven central repository
repositories {
maven {
name = "sonatype"
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = getExtraString("ossrhUsername")
password = getExtraString("ossrhPassword")
}
}
}

// Configure all publications
publications.withType<MavenPublication> {
// Stub javadoc.jar artifact
artifact(javadocJar.get())

// Provide artifacts information requited by Maven Central
pom {
name.set("Flatbuffers Kotlin")
description.set("Memory Efficient Serialization Library")
url.set("https://github.com/google/flatbuffers")

licenses {
license {
name.set("Apache License V2.0")
url.set("https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE")
}
}
developers {
developer {
id.set("https://github.com/paulovap")
name.set("Paulo Pinheiro")
email.set("paulovictor.pinheiro@gmail.com")
}
developer {
id.set("https://github.com/dbaileychess")
name.set("Derek Bailey")
email.set("dbaileychess@gmail.com")
}
}
scm {
url.set("https://github.com/google/flatbuffers")
}
}
}
}

// Signing artifacts. Signing.* extra properties values will be used
signing {
sign(publishing.publications)
}
1 change: 1 addition & 0 deletions kotlin/flatbuffers-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig

plugins {
kotlin("multiplatform")
id("convention.publication")
}


Expand Down
1 change: 1 addition & 0 deletions kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
rootProject.name = "flatbuffers-kotlin"
includeBuild("convention-plugins")
include("flatbuffers-kotlin")
include("benchmark")
10 changes: 10 additions & 0 deletions tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@rules_cc//cc:defs.bzl", "cc_test")
load("//:build_defs.bzl", "DEFAULT_FLATC_ARGS", "flatbuffer_cc_library")
load(":defs.bzl", "flatbuffers_as_external_repo_test")

package(default_visibility = ["//visibility:private"])

exports_files([
"bazel_repository_test_template.sh",
])

# rules_js works around various JS tooling limitations by copying everything
# into the output directory. Make the test data available to the tests this way.
copy_to_bin(
Expand Down Expand Up @@ -264,3 +269,8 @@ flatbuffer_cc_library(
name = "alignment_test_cc_fbs",
srcs = ["alignment_test.fbs"],
)

flatbuffers_as_external_repo_test(
name = "bazel_repository_test",
directory = "bazel_repository_test_dir",
)
1 change: 1 addition & 0 deletions tests/bazel_repository_test_dir/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build --symlink_prefix=/
1 change: 1 addition & 0 deletions tests/bazel_repository_test_dir/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
10 changes: 10 additions & 0 deletions tests/bazel_repository_test_dir/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This test doesn't actually make use of the flatbuffers library. It's just
# here to make sure we can link the library properly when it comes from an
# external repository. You're welcome to expand this test to do more.
cc_test(
name = "pulls_in_flatbuffers_test",
srcs = ["pulls_in_flatbuffers_test.cpp"],
deps = [
"@com_github_google_flatbuffers//:flatbuffers",
],
)
8 changes: 8 additions & 0 deletions tests/bazel_repository_test_dir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This directory is not intended to be used independently of the flatbuffers
repository. Instead, this whole directory serves as a unit test for the
C++ integration in the flatbuffers repo.

Run this test from the top-level of the flatbuffers repo.
```console
$ bazel test //tests:bazel_repository_test
```
6 changes: 6 additions & 0 deletions tests/bazel_repository_test_dir/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
workspace(name = "bazel_repository_test")

local_repository(
name = "com_github_google_flatbuffers",
path = "../../",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int main() { return 0; }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This test makes sure that a separate repository can import the flatbuffers
# repository and use it in their JavaScript code.
# repository and use it in their code.

# --- begin runfiles.bash initialization v3 ---
# Copy-pasted from the Bazel Bash runfiles library v3.
Expand All @@ -24,6 +24,6 @@ fi

export PATH="$(dirname "${BAZEL_BIN}"):${PATH}"

cd tests/ts/bazel_repository_test_dir/
cd {{REPOSITORY_DIR}}

bazel test //...

0 comments on commit 9ba1658

Please sign in to comment.