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
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: CI

Check warning on line 1 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:1: overly broad permissions: default permissions used due to no permissions: block
on: [push, pull_request, workflow_dispatch]
jobs:
# C implementation. Lives in c/, tested with bazel.
test-c:

Check warning on line 5 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:5: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: c
steps:
- uses: actions/checkout@v4

Check failure on line 10 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 10 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:10: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- uses: bazelbuild/setup-bazelisk@v3

Check failure on line 11 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 11 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:11: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- name: test
run: bazel test --test_output=all ${OLC_PATH}:all
- name: check formatting
Expand All @@ -17,37 +17,37 @@
# C implementation. Lives in c/, tested with bazel.
# Use Mac with Apple Silicon for this test because of different floating point math
# which can affect test results https://github.com/google/open-location-code/issues/652
test-c-macos-latest:

Check warning on line 20 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:20: overly broad permissions: default permissions used due to no permissions: block
runs-on: macos-latest
env:
OLC_PATH: c
steps:
- uses: actions/checkout@v4

Check failure on line 25 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 25 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:25: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- uses: bazelbuild/setup-bazelisk@v3

Check failure on line 26 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 26 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:26: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- name: test
run: bazel test --test_output=all ${OLC_PATH}:all

# C++ implementation. Lives in cpp/, tested with bazel.
test-cpp:

Check warning on line 31 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:31: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: cpp
steps:
- uses: actions/checkout@v4

Check failure on line 36 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 36 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:36: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- uses: bazelbuild/setup-bazelisk@v3

Check failure on line 37 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 37 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:37: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- name: test
run: bazel test --test_output=all ${OLC_PATH}:all
- name: check formatting
run: cd ${OLC_PATH} && bash clang_check.sh

# Dart implementation. Lives in dart/.
test-dart:

Check warning on line 44 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:44: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: dart
steps:
- uses: actions/checkout@v4

Check failure on line 49 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 49 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:49: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- uses: dart-lang/setup-dart@v1

Check failure on line 50 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 50 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:50: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- name: test
run: |
cd ${OLC_PATH}
Expand All @@ -55,13 +55,13 @@
bash checks.sh

# Go implementation. Lives in go/. Tests fail if files have not been formatted with gofmt.
test-go:

Check warning on line 58 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:58: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: go
steps:
- uses: actions/checkout@v4

Check failure on line 63 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

zizmor/unpinned-uses

unpinned action reference: action is not pinned to a hash (required by blanket policy)

Check failure on line 63 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:63: unpinned action reference: action is not pinned to a hash (required by blanket policy)
- uses: actions/setup-go@v5

Check failure on line 64 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

unpinned-uses

main.yml:64: unpinned action reference: action is not pinned to a hash (required by blanket policy)
with:
go-version: '1.23'
- name: test
Expand All @@ -75,7 +75,7 @@
go test ./ -v

# Java implementation. Lives in java/, tested with bazel and maven.
test-java:

Check warning on line 78 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:78: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: java
Expand All @@ -95,7 +95,7 @@
run: bazel test --test_output=all ${OLC_PATH}:all && cd ${OLC_PATH} && mvn package -Dsurefire.useFile=false -DdisableXmlReport=true

# Javascript Closure library implementation. Lives in js/closure, tested with bazel.
test-js-closure:

Check warning on line 98 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:98: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: js/closure
Expand All @@ -108,7 +108,7 @@
cd js && npm install && ./node_modules/.bin/eslint closure/*js

# Javascript implementation. Lives in js/.
test-js:

Check warning on line 111 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:111: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: js
Expand All @@ -120,7 +120,7 @@
bash checks.sh

# Python implementation. Lives in python/, tested with bazel.
test-python:

Check warning on line 123 in .github/workflows/main.yml

View workflow job for this annotation

GitHub Actions / zizmor-output

excessive-permissions

main.yml:123: overly broad permissions: default permissions used due to no permissions: block
runs-on: ubuntu-latest
env:
OLC_PATH: python
Expand Down Expand Up @@ -161,6 +161,30 @@
cd ${OLC_PATH} && ruby test/plus_codes_test.rb
rubocop --config rubocop.yml

# Kotoba implementation. Lives in kotoba/. Compiles .kotoba to wasm with
# kotoba CLI v0.7.2 and runs vendored Plus Code fixtures.
test-kotoba:
runs-on: ubuntu-latest
env:
OLC_PATH: kotoba
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install kotoba CLI v0.7.2
run: |
curl -fsSL -o /tmp/kotoba-linux-amd64.tar.gz \
https://github.com/kotoba-lang/kotoba/releases/download/v0.7.2/kotoba-linux-amd64.tar.gz
echo "95e225461e1b8a21849b251e8c8b654693d2c8a516b258532771651e978e1977 /tmp/kotoba-linux-amd64.tar.gz" | sha256sum -c
mkdir -p /tmp/kotoba-cli
tar -xzf /tmp/kotoba-linux-amd64.tar.gz -C /tmp/kotoba-cli
sudo install -m 755 /tmp/kotoba-cli/kotoba /usr/local/bin/kotoba
- name: test
run: |
cd ${OLC_PATH}
bash checks.sh

# Rust implementation. Lives in rust/.
test-rust:
runs-on: ubuntu-latest
Expand Down
51 changes: 51 additions & 0 deletions kotoba/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Kotoba library for Open Location Code

This is a Plus Code (Open Location Code) encode/decode binding for
[Kotoba](https://github.com/kotoba-lang/kotoba) CLI v0.7.2.

Kotoba cannot FFI. The implementation is self-contained in
`openlocationcode.kotoba` and compiles to host-independent wasm32 (`i64-v1`).

## Integers only (microdegrees)

The v0.7.2 wasm32 backend has no IEEE floats. Coordinates are **microdegrees**
(`i64`): 1 unit = 1e-6 degree. A Plus Code is two little-endian i64 words of
ASCII (word 0 = chars 0–7, word 1 = chars 8–15; unused bytes are 0).

This matches the integer path in `go/encode.go` / `go/decode.go`, not the
float `Encode`/`Decode` wrappers in other language directories.

## Public API

| Function | Arguments | Result |
| --- | --- | --- |
| `encode-word` | `lat-udeg`, `lng-udeg`, `code-len`, `word-ix` | packed ASCII word (`0` or `1`) |
| `encode-char` | `lat-udeg`, `lng-udeg`, `code-len`, `pos` | ASCII code unit |
| `decode-lat-lo` / `decode-lng-lo` | `w0`, `w1` | south-west corner, microdegrees |
| `decode-lat-hi` / `decode-lng-hi` | `w0`, `w1` | north-east corner, microdegrees |
| `decode-len` | `w0`, `w1` | significant digit count |
| `main` | (none) | `0` if vendored fixtures pass |

v1 covers full-code encode/decode only (no shorten/recover).

## Testing

From this directory, with kotoba CLI v0.7.2 and Node.js on `PATH`:

```
bash checks.sh
```

`checks.sh` compiles `openlocationcode.kotoba` to wasm, checks the module has
wasm magic and no imports, instantiates it twice (wasm fuel is per-instance),
requires `main() === 0` for encode fixtures, then calls the decode exports
against the vendored vectors.

Fixtures in `testdata/` are a subset of `../test_data/encoding.csv` and
`../test_data/decoding.csv`, converted to microdegrees.

## Compile

```
kotoba compile openlocationcode.kotoba --target wasm --output openlocationcode.wasm --json
```
15 changes: 15 additions & 0 deletions kotoba/checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
# Compile the Kotoba Open Location Code binding and run vendored fixtures.
# Must run from within the kotoba directory.
if [ "$(basename "$PWD")" != "kotoba" ]; then
echo "$0: must be run from within the kotoba directory!"
exit 1
fi

set -euo pipefail

KOTOBA_BIN="${KOTOBA:-kotoba}"
OUT="${TMPDIR:-/tmp}/openlocationcode.wasm"

"$KOTOBA_BIN" compile openlocationcode.kotoba --target wasm --output "$OUT" --json
node run_wasm.mjs "$OUT"
Loading
Loading