diff --git a/.github/workflows/kmp-pull-request.yml b/.github/workflows/kmp-pull-request.yml new file mode 100644 index 00000000..ca934e88 --- /dev/null +++ b/.github/workflows/kmp-pull-request.yml @@ -0,0 +1,33 @@ +name: kmp-pull-request + +on: + pull_request: + paths: + - "meshtastic/**/*.proto" + - "nanopb.proto" + - "packages/kmp/**" + +permissions: + contents: read + +jobs: + build-kmp: + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build KMP package + run: packages/kmp/gradlew --no-daemon -p packages/kmp build -PVERSION_NAME=0.0.0-pr diff --git a/.github/workflows/publish-kmp.yml b/.github/workflows/publish-kmp.yml new file mode 100644 index 00000000..2fe0c535 --- /dev/null +++ b/.github/workflows/publish-kmp.yml @@ -0,0 +1,95 @@ +name: Publish KMP package + +on: + push: + tags: + - "v*" + workflow_dispatch: + inputs: + version: + description: "Version to publish (e.g. v1.2.3). Used when manually dispatching." + required: false + type: string + dry_run: + description: "Dry run mode - build and publish to Maven Local only" + required: false + type: boolean + default: false + +permissions: + contents: read + +jobs: + build-kmp: + runs-on: macos-latest + outputs: + version: ${{ steps.version.outputs.VERSION }} + tag: ${{ steps.version.outputs.TAG }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Determine version + id: version + run: | + set -euo pipefail + if [ "${{ github.ref_type }}" = "tag" ]; then + TAG="${{ github.ref_name }}" + elif [ -n "${{ inputs.version || '' }}" ]; then + TAG="${{ inputs.version }}" + else + echo "No tag ref and no 'version' input. Provide a tag or pass inputs.version." >&2 + exit 1 + fi + VERSION="${TAG#v}" + echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" + echo "TAG=$TAG" >> "$GITHUB_OUTPUT" + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build KMP package + run: packages/kmp/gradlew --no-daemon -p packages/kmp clean build -PVERSION_NAME=${{ steps.version.outputs.VERSION }} + + - name: Publish to Maven Local + run: packages/kmp/gradlew --no-daemon -p packages/kmp publishToMavenLocal -PVERSION_NAME=${{ steps.version.outputs.VERSION }} + + publish-kmp: + runs-on: macos-latest + needs: build-kmp + if: ${{ !inputs.dry_run }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Publish to Maven Central + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_SIGNING_KEY }} + run: packages/kmp/gradlew --no-daemon -p packages/kmp publishAllPublicationsToMavenCentralRepository -PVERSION_NAME=${{ needs.build-kmp.outputs.version }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c8991fef..89e5aec6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -48,9 +48,8 @@ jobs: echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT" echo "TAG=$TAG" >> "$GITHUB_OUTPUT" echo "Resolved VERSION=$VERSION, TAG=$TAG" - - name: Setup Buf - uses: bufbuild/buf-setup-action@main + uses: bufbuild/buf-setup-action@v1.50.0 with: github_token: ${{ github.token }} @@ -62,17 +61,14 @@ jobs: set -euo pipefail src_dir="packages/ts/lib/meshtastic" dest_dir="packages/ts/lib" - if [ ! -d "$src_dir" ]; then echo "Expected source directory '$src_dir' does not exist. 'buf generate' may have failed or changed its output paths." >&2 exit 1 fi - if ! compgen -G "$src_dir"/*_pb.ts > /dev/null; then echo "No '*_pb.ts' files found in '$src_dir'. 'buf generate' may have produced no TypeScript files or changed their naming." >&2 exit 1 fi - mv "$src_dir"/*_pb.ts "$dest_dir"/ - name: Show generated files run: | @@ -80,7 +76,6 @@ jobs: ls -la packages/ts/ echo "=== packages/ts/lib contents ===" ls -la packages/ts/lib/ || echo "lib folder not found" - - name: Set package versions run: | set -euo pipefail @@ -89,7 +84,6 @@ jobs: test -f "$f" || { echo "Missing $f" >&2; exit 1; } sed -i "s/__PACKAGE_VERSION__/${VERSION}/g" "$f" done - - name: Copy license & README run: cp LICENSE README.md packages/ts/ @@ -116,11 +110,10 @@ jobs: ls -la echo "=== lib/ contents ===" ls -la lib/ || echo "lib folder not found" - - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "22" + node-version: "24" - name: Install dependencies run: npm install @@ -133,7 +126,6 @@ jobs: echo "=== Build output ===" ls -la ls -la dist/ - - name: Upload built NPM package uses: actions/upload-artifact@v4 with: @@ -143,7 +135,6 @@ jobs: package.json LICENSE README.md - - name: Upload JSR package uses: actions/upload-artifact@v4 with: @@ -154,7 +145,6 @@ jobs: deno.json LICENSE README.md - create-release-zips: runs-on: ubuntu-24.04 needs: [codegen, build-typescript] @@ -175,7 +165,6 @@ jobs: run: | cd npm_package && zip -r ../meshtastic-protobufs-npm.zip . && cd .. cd jsr_package && zip -r ../meshtastic-protobufs-jsr.zip . && cd .. - - name: Upload release zips uses: actions/upload-artifact@v4 with: @@ -183,7 +172,6 @@ jobs: path: | meshtastic-protobufs-npm.zip meshtastic-protobufs-jsr.zip - upload-release-assets: runs-on: ubuntu-24.04 needs: [codegen, create-release-zips] @@ -201,7 +189,6 @@ jobs: files: | meshtastic-protobufs-npm.zip meshtastic-protobufs-jsr.zip - push-buf-registry: runs-on: ubuntu-24.04 needs: codegen @@ -211,7 +198,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Buf - uses: bufbuild/buf-setup-action@main + uses: bufbuild/buf-setup-action@v1.50.0 with: github_token: ${{ github.token }} @@ -224,9 +211,6 @@ jobs: runs-on: ubuntu-24.04 needs: [codegen, build-typescript] if: ${{ !inputs.dry_run }} - permissions: - contents: read - id-token: write steps: - name: Download NPM package uses: actions/download-artifact@v4 @@ -236,14 +220,13 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "22" + node-version: "24" registry-url: "https://registry.npmjs.org" - - name: Install NPM CLI - run: npm install -g npm@latest - - name: Publish to NPM - run: npm publish + run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} publish-jsr: runs-on: ubuntu-24.04 @@ -261,7 +244,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: "22" + node-version: "24" - name: Publish to JSR - run: npx jsr publish + run: npx jsr publish --allow-dirty diff --git a/.github/workflows/snapshot-kmp.yml b/.github/workflows/snapshot-kmp.yml new file mode 100644 index 00000000..4b7c324e --- /dev/null +++ b/.github/workflows/snapshot-kmp.yml @@ -0,0 +1,59 @@ +name: Publish KMP snapshot + +on: + push: + branches: + - master + paths: + - "meshtastic/**/*.proto" + - "nanopb.proto" + - "packages/kmp/**" + +permissions: + contents: read + +jobs: + publish-snapshot: + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Compute snapshot version + id: version + run: | + TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0") + RELEASE_VERSION="${TAG#v}" + IFS='.' read -r major minor patch <<< "$RELEASE_VERSION" + SNAPSHOT_VERSION="${major}.${minor}.$((patch + 1))-SNAPSHOT" + echo "snapshot=$SNAPSHOT_VERSION" >> "$GITHUB_OUTPUT" + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "21" + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build KMP package + run: packages/kmp/gradlew --no-daemon -p packages/kmp build -PVERSION_NAME=${{ steps.version.outputs.snapshot }} + + - name: Publish snapshot to Maven Central + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_SIGNING_KEY }} + run: | + set -euo pipefail + if [ -z "${ORG_GRADLE_PROJECT_mavenCentralUsername}" ] || [ -z "${ORG_GRADLE_PROJECT_mavenCentralPassword}" ]; then + echo "Missing Maven Central secrets — skipping snapshot publish." >&2 + exit 0 + fi + packages/kmp/gradlew --no-daemon -p packages/kmp publishAllPublicationsToMavenCentralRepository -PVERSION_NAME=${{ steps.version.outputs.snapshot }} diff --git a/.gitignore b/.gitignore index dd68173b..8d2e8b04 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ # Generated protobuf files packages/ts/lib/ +packages/kmp/.gradle/ +packages/kmp/build/ .bin/ diff --git a/README.md b/README.md index 9e361977..a2c26642 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,12 @@ The [Protobuf](https://developers.google.com/protocol-buffers) message definitio **[Documentation/API Reference](https://buf.build/meshtastic/protobufs)** +## Generated client packages + +- TypeScript package: `packages/ts` +- Rust package: `packages/rust` +- Kotlin Multiplatform package (Wire): `packages/kmp` + ## Stats ![Alt](https://repobeats.axiom.co/api/embed/47e9ee1d81d9c0fdd2b4b5b4c673adb1756f6db5.svg "Repobeats analytics image") diff --git a/meshtastic/mesh.proto b/meshtastic/mesh.proto index 9527ec8c..c48a7371 100644 --- a/meshtastic/mesh.proto +++ b/meshtastic/mesh.proto @@ -913,6 +913,26 @@ enum HardwareModel { */ T_ECHO_CARD = 136; + /* + * Seeed Tracker L2 + */ + SEEED_WIO_TRACKER_L2 = 137; + + /* + * Elecrow CrowPanel Advance P4 models, ESP32-P4 and TFT with SX1262 radio plugin + */ + CROWPANEL_P4 = 138; + + /* + * Heltec Mesh Tower V2 + */ + HELTEC_MESH_TOWER_V2 = 139; + + /* + * Meshnology W10 + */ + MESHNOLOGY_W10 = 140; + /* * ------------------------------------------------------------------------------------------------------------------------------------------ * Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. diff --git a/packages/kmp/README.md b/packages/kmp/README.md new file mode 100644 index 00000000..494304a7 --- /dev/null +++ b/packages/kmp/README.md @@ -0,0 +1,95 @@ +# Meshtastic Protobufs (KMP) + +This package publishes Kotlin Multiplatform models generated from the protobuf schema in this repository using [Square Wire](https://square.github.io/wire/). + +## What this provides + +- A single generated-model source of truth for downstream Kotlin and KMP clients. +- Kotlin/Android, Kotlin/JVM, Kotlin/JS, Kotlin/Wasm (`wasmJs` and `wasmWasi`), and Kotlin/Native artifacts from the same protobuf schema. +- Wire runtime-based models in the existing protobuf namespace (`meshtastic` package from `.proto`). +- Wire reads schema sources from `packages/kmp/proto/`, which symlinks back to the repo-root proto files. + +> This package publishes Kotlin/KMP artifacts to Maven repositories. Native Swift-only distribution (for example an XCFramework/SPM package) is a separate delivery path and is not part of this module. + +## Versioning + +The SDK version is derived automatically from the latest git tag — no manual version file to maintain. + +| Context | Version | Source | +|---------|---------|--------| +| Release CI (`v2.7.23` tag push) | `2.7.23` | Tag stripped of `v` prefix, passed as `-PVERSION_NAME` | +| Snapshot CI (master push) | `2.7.24-SNAPSHOT` | Latest tag + patch bump, computed in workflow | +| Local dev (no flag) | `2.7.24-SNAPSHOT` | `git describe --tags --abbrev=0` + patch bump | +| Local override | any | `./gradlew build -PVERSION_NAME=x.y.z` | + +If no `-PVERSION_NAME` is supplied and no tag can be resolved (git missing, or a +shallow/tagless clone), the fallback degrades to `0.0.1-SNAPSHOT` rather than +failing the build. + +## Maven coordinates + +```kotlin +// build.gradle.kts +implementation("org.meshtastic:protobufs:2.7.23") + +// Platform-specific artifacts (resolved automatically by Gradle KMP): +// org.meshtastic:protobufs-android +// org.meshtastic:protobufs-jvm +// org.meshtastic:protobufs-js +// org.meshtastic:protobufs-wasm-js +// org.meshtastic:protobufs-wasm-wasi +// org.meshtastic:protobufs-iosx64 +// org.meshtastic:protobufs-iosarm64 +// org.meshtastic:protobufs-iossimulatorarm64 +// org.meshtastic:protobufs-tvosarm64 +// org.meshtastic:protobufs-tvossimulatorarm64 +// org.meshtastic:protobufs-macosarm64 +// org.meshtastic:protobufs-linuxx64 +// org.meshtastic:protobufs-linuxarm64 +// org.meshtastic:protobufs-mingwx64 +``` + +### Snapshots + +Snapshot builds (published from `master`) live in the Central Portal snapshots +repository, not on the main Maven Central CDN. To consume them, add that +repository alongside `mavenCentral()` and depend on a `-SNAPSHOT` version: + +```kotlin +// settings.gradle.kts (or build.gradle.kts) +repositories { + mavenCentral() + maven("https://central.sonatype.com/repository/maven-snapshots/") { + mavenContent { snapshotsOnly() } + } +} + +// build.gradle.kts +implementation("org.meshtastic:protobufs:2.7.24-SNAPSHOT") +``` + +## Local build + +```bash +packages/kmp/gradlew -p packages/kmp clean build +``` + +## Publish locally + +```bash +packages/kmp/gradlew -p packages/kmp publishToMavenLocal -PVERSION_NAME=2.7.23 +``` + +## Publish to Maven Central + +Set these environment variables: + +- `ORG_GRADLE_PROJECT_mavenCentralUsername` +- `ORG_GRADLE_PROJECT_mavenCentralPassword` +- `ORG_GRADLE_PROJECT_signingInMemoryKey` (ASCII-armored private key) + +Then run: + +```bash +packages/kmp/gradlew -p packages/kmp publishAllPublicationsToMavenCentralRepository -PVERSION_NAME=2.7.23 +``` diff --git a/packages/kmp/build.gradle.kts b/packages/kmp/build.gradle.kts new file mode 100644 index 00000000..6be776ad --- /dev/null +++ b/packages/kmp/build.gradle.kts @@ -0,0 +1,154 @@ +plugins { + kotlin("multiplatform") version "2.3.21" + id("com.android.kotlin.multiplatform.library") version "9.2.1" + id("com.squareup.wire") version "6.4.0" + id("com.vanniktech.maven.publish") version "0.36.0" +} + +group = providers.gradleProperty("GROUP").get() +version = providers.gradleProperty("VERSION_NAME").orElse( + providers.provider { + // Fallback for local builds with no -PVERSION_NAME (CI always passes it): + // derive a snapshot version by patch-bumping the latest git tag. Any + // failure — git missing, shallow/tagless clone, or an unexpected tag + // format — degrades to 0.0.1-SNAPSHOT instead of breaking configuration. + val tag = runCatching { + val process = ProcessBuilder("git", "describe", "--tags", "--abbrev=0") + .directory(rootDir) + .start() + val out = process.inputStream.bufferedReader().readText().trim() + if (process.waitFor() == 0) out else "" + }.getOrDefault("") + + val parts = tag.removePrefix("v").split(".") + val major = parts.getOrNull(0)?.toIntOrNull() ?: 0 + val minor = parts.getOrNull(1)?.toIntOrNull() ?: 0 + val patch = parts.getOrNull(2)?.toIntOrNull() ?: 0 + "$major.$minor.${patch + 1}-SNAPSHOT" + } +).get() + +repositories { + google() + mavenCentral() +} + +@OptIn(org.jetbrains.kotlin.gradle.ExperimentalWasmDsl::class) +kotlin { + android { + namespace = "org.meshtastic.proto" + compileSdk = 37 + minSdk = 24 + } + jvm() + js { + browser() + nodejs() + } + wasmJs { + browser() + } + wasmWasi { + nodejs() + } + macosArm64() + linuxX64() + linuxArm64() + mingwX64() + iosX64() + iosArm64() + iosSimulatorArm64() + tvosArm64() + tvosSimulatorArm64() + + sourceSets { + commonMain { + dependencies { + api("com.squareup.wire:wire-runtime:6.4.0") + } + } + } + + // Suppress warnings in Wire-generated code + compilerOptions { + freeCompilerArgs.add("-Xwarning-level=UNNECESSARY_NOT_NULL_ASSERTION:disabled") + } +} + +tasks.withType().configureEach { + from(rootProject.layout.projectDirectory.file("../../LICENSE")) +} + +val repoRoot = rootProject.layout.projectDirectory.dir("../../") + +val syncProtos by tasks.registering(Sync::class) { + from(repoRoot.dir("meshtastic")) + into(layout.buildDirectory.dir("protos/meshtastic")) +} + +val syncNanopb by tasks.registering(Sync::class) { + from(repoRoot.file("nanopb.proto")) + into(layout.buildDirectory.dir("protos")) +} + +wire { + sourcePath { + srcDir(layout.buildDirectory.dir("protos")) + include("meshtastic/**/*.proto") + include("nanopb.proto") + } + kotlin { + includes = listOf("meshtastic.*") + + // Flatten oneof fields into nullable properties on the parent message + // class instead of generating intermediate sealed classes. All consumers + // (Meshtastic-Android, TAKPacket-SDK) are written against this shape — + // e.g. `packet.decoded`, `packet.chat`, `takPacketV2.shape` are all + // nullable top-level properties, not sealed-class arms. + boxOneOfsMinSize = 5000 + + // Skip defensive immutable copies of repeated/map fields on decode. + // Reduces allocations on high-frequency decode paths (mesh packets). + makeImmutableCopies = false + } +} + +// Ensure protos are synced before Wire generates code +afterEvaluate { + tasks.matching { it.name.startsWith("generate") && it.name.endsWith("Protos") }.configureEach { + dependsOn(syncProtos, syncNanopb) + } +} + +mavenPublishing { + publishToMavenCentral(automaticRelease = true) + if (providers.gradleProperty("signingInMemoryKey").isPresent) { + signAllPublications() + } + + pom { + name.set("Meshtastic Protobufs") + description.set("Kotlin Multiplatform Wire models generated from Meshtastic protobuf definitions.") + inceptionYear.set("2025") + url.set("https://github.com/meshtastic/protobufs") + licenses { + license { + name.set("GNU General Public License, Version 3.0") + url.set("https://www.gnu.org/licenses/gpl-3.0.html") + distribution.set("repo") + } + } + developers { + developer { + id.set("meshtastic") + name.set("Meshtastic") + url.set("https://meshtastic.org") + } + } + scm { + url.set("https://github.com/meshtastic/protobufs") + connection.set("scm:git:git://github.com/meshtastic/protobufs.git") + developerConnection.set("scm:git:ssh://git@github.com/meshtastic/protobufs.git") + } + } +} diff --git a/packages/kmp/gradle.properties b/packages/kmp/gradle.properties new file mode 100644 index 00000000..c2d171a3 --- /dev/null +++ b/packages/kmp/gradle.properties @@ -0,0 +1,9 @@ +org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8 +org.gradle.caching=true +org.gradle.parallel=true +kotlin.code.style=official +kotlin.daemon.jvmargs=-Xmx4096m + +# Publishing coordinates (picked up by com.vanniktech.maven.publish) +GROUP=org.meshtastic +POM_ARTIFACT_ID=protobufs diff --git a/packages/kmp/gradle/wrapper/gradle-wrapper.jar b/packages/kmp/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..b1b8ef56 Binary files /dev/null and b/packages/kmp/gradle/wrapper/gradle-wrapper.jar differ diff --git a/packages/kmp/gradle/wrapper/gradle-wrapper.properties b/packages/kmp/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..df6a6ad7 --- /dev/null +++ b/packages/kmp/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,9 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/packages/kmp/gradlew b/packages/kmp/gradlew new file mode 100755 index 00000000..b9bb139f --- /dev/null +++ b/packages/kmp/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015 the original authors. +# +# 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 +# +# https://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. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/packages/kmp/gradlew.bat b/packages/kmp/gradlew.bat new file mode 100644 index 00000000..24c62d56 --- /dev/null +++ b/packages/kmp/gradlew.bat @@ -0,0 +1,82 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +"%COMSPEC%" /c exit 1 + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel + +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/packages/kmp/settings.gradle.kts b/packages/kmp/settings.gradle.kts new file mode 100644 index 00000000..89b3f9e7 --- /dev/null +++ b/packages/kmp/settings.gradle.kts @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + google() + gradlePluginPortal() + mavenCentral() + } +} + +dependencyResolutionManagement { + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "protobufs"