git.iko.soy/rowtype-yoga/purescript-protobuf
on master help sign in
Github CI
commit82043bbab11bb3d29b47c9b4a2bc57d2b9e6962a authorJames Brock <jamesbrock@gmail.com> dateMon 2 Dec 2024, 11:17 (2 years ago) parentef7f471
9 files changed+89−32
.github/workflows/ci.yml+42−20 .vscode/settings.json+1−1 README.md+20−8 bin/conformance-purescript+1−1 bin/protoc-gen-purescript+1−1 conformance/README.md+8 flake.nix+2−1 plugin/README.md+9 plugin/test/README.md+5
.github/workflows/ci.yml+42−20
@@ -10,48 +10,70 @@ jobs:
1010 runs-on: ubuntu-latest
1111
1212 steps:
13− - uses: actions/checkout@v2
1413 # https://github.com/marketplace/actions/cache-apt-packages
14+ - uses: actions/checkout@v4
1515 - uses: awalsh128/cache-apt-pkgs-action@latest
1616 with:
1717 packages: protobuf-compiler
1818
19+ # https://github.com/purescript-contrib/setup-purescript/
1920 - name: Set up a PureScript toolchain
2021 uses: purescript-contrib/setup-purescript@main
2122 with:
2223 purescript: "unstable"
2324 purs-tidy: "latest"
25+ spago: "unstable"
2426
27+ # https://github.com/marketplace/actions/cache
2528 - name: Cache PureScript dependencies
26− uses: actions/cache@v2
29+ uses: actions/cache@v4
2730 with:
28− key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}-2
31+ key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}-2
2932 path: |
30− .spago
31− output
33+ ./plugin/.spago
34+ ./conformance/.spago
3235
3336 - name: Install dependencies
34− run: spago install
37+ run: |
38+ protoc --version
39+ echo -n "node "
40+ node --version
41+ echo -n "purs "
42+ purs --version
43+ echo -n "spago "
44+ spago --version
45+ echo ""
46+ spago install
3547
36− - name: Install plugin dependencies
37− run: spago -x spago-plugin.dhall install
48+ - name: Build Plugin
49+ run: |
50+ cd plugin
51+ spago build
3852
39− - name: Install test dependencies
40− run: spago -x spago-test.dhall install
53+ - name: Test Plugin
54+ # Need --experimental_allow_proto3_optional until the CI protoc is upgraded
55+ run: |
56+ protoc --experimental_allow_proto3_optional --plugin=bin/protoc-gen-purescript --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
57+ cd plugin
58+ spago test
4159
42− - name: Build plugin
43− run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''
60+ # - name: Install test dependencies
61+ # run: spago -x spago-test.dhall install
4462
45− - run: mkdir -p ./test/generated
63+ # - name: Build plugin
64+ # run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''
4665
47− - name: Generate test from .proto
48− run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto
66+ # - run: mkdir -p ./test/generated
4967
50− - name: Build test
51− run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''
68+ # - name: Generate test from .proto
69+ # run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto
5270
53− - name: Run tests
54− run: spago -x spago-test.dhall test --no-install
71+ # - name: Build test
72+ # run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''
73+
74+ # - name: Run tests
75+ # run: spago -x spago-test.dhall test --no-install
5576
5677 # We're not running the conformance test because the conformance
57− # test runner is a pretty heavy build.
78+ # test runner is a pretty heavy build.
79+
.vscode/settings.json+1−1
@@ -1,3 +1,3 @@
11{
2− "purescript.buildCommand": "spago -x spago-dev.dhall build --purs-args --json-errors",
2+ "purescript.buildCommand": "spago build --json-errors",
33}
README.md+20−8
@@ -67,19 +67,30 @@ To compile PureScript .purs files from .proto files, run for example:
6767
6868We can test out code generation immediately by
6969generating `.purs` files for any of Google’s built-in “well-known types” in the
70−[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command `protoc --purescript_out=. google/protobuf/any.proto`
71−or `protoc --purescript_out=. google/protobuf/timestamp.proto`.
70+[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command
71+```console
72+protoc --purescript_out=. google/protobuf/any.proto
73+```
74+or
75+```console
76+protoc --purescript_out=. google/protobuf/timestamp.proto
77+```
7278
7379To see
7480[all of the `.proto` definitions](https://github.com/protocolbuffers/protobuf/tree/main/src/google/protobuf)
7581included with the Nix PureScript Protobuf installation including
7682the “well-known types,”
77−`ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto`
83+```console
84+ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto
85+```
7886
79−If you don't want to use Nix, then install the PureScript toolchain and `protoc`,
80−and add the executable script
81−[`bin/protoc-gen-purescript`](bin/protoc-gen-purescript)
82−to your `PATH`.
87+If you don't want to use Nix,
88+1. install the PureScript toolchain and `protoc`.
89+2. Build the [PureScript plugin for `protoc`](plugin/).
90+3. Run `protoc` with the path to the PureScript plugin executable, like for example
91+ ```console
92+ protoc --plugin=bin/protoc-gen-purescript --purescript_out=. google/protobuf/timestamp.proto
93+ ```
8394
8495## Writing programs with the generated code
8596
@@ -318,10 +329,11 @@ For that reason, we can only use top-level
318329### PureScript Imports
319330
320331The generated PureScript code will usually have module imports which cause
321−the `purs` compiler to emit redundant import warnings. Sorry. If this causes
332+the `purs` compiler to emit `ImplicitQualifiedImport` warnings. Sorry. If this causes
322333trouble then the imports can be fixed automatically in a precompiling pass
323334with the command-line tool
324335[__suggest__](https://github.com/nwolverson/purescript-suggest).
336+Or you can [censor the warnings](https://discourse.purescript.org/t/suppressing-warnings-in-code/2485).
325337
326338## Nix derivation
327339
bin/conformance-purescript+1−1
@@ -1,2 +1,2 @@
11#!/usr/bin/env bash
2−node --input-type=module --abort-on-uncaught-exception --trace-sigint --trace-uncaught -e "import {main} from 'conformance/output/Conformance.Main/index.js'; main();"
2+node --input-type=module --abort-on-uncaught-exception --trace-sigint --trace-uncaught -e "import {main} from './conformance/output/Main/index.js'; main();"
bin/protoc-gen-purescript+1−1
@@ -1,2 +1,2 @@
11#!/usr/bin/env bash
2−node --input-type=module -e "import {main} from 'plugin/output/ProtocPlugin.Main/index.js'; main();"
2+node --input-type=module -e "import {main} from './plugin/output/ProtocPlugin.Main/index.js'; main();"
conformance/README.md+8
@@ -7,6 +7,14 @@ From the top directory of this repo,
77```console
88nix run .#conformance
99```
10+or
11+```console
12+cd conformance
13+spago build
14+```
15+```console
16+conformance_test_runner --enforce_recommended bin/conformance-purescript
17+```
1018
1119## About the conformance test runner
1220
flake.nix+2−1
@@ -111,10 +111,11 @@
111111 protoc-gen-purescript
112112 ];
113113
114+ # spago sources not working, TODO
114115 shellHook = ''
115116 source <(spago --bash-completion-script `which spago`)
116117 source <(node --completion-bash)
117− export PURS_IDE_SOURCES=$(pushd plugin;${pkgs.spago-unstable}/bin/spago sources;popd)
118+ export PURS_IDE_SOURCES=$(spago sources --package protobuf)
118119 echo "PureScript Protobuf development environment"
119120 protoc --version
120121 echo -n "node "
plugin/README.md+9
@@ -1,3 +1,12 @@
1+
2+# PureScript plugin for Protoc
3+
4+Build:
5+
6+```
7+spago build
8+```
9+
110The funny thing about writing a `protoc` compiler plugin codec is that it
211bootstraps itself. We just have to write enough of the compiler plugin codec
312that it can handle the `plugin.proto` and `descriptor.proto` files, and
plugin/test/README.md+5
@@ -9,6 +9,11 @@ of the repo, then:
99```console
1010protoc --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
1111```
12+or, for the plugin from src tree, not the Nix store,
13+``console
14+protoc --plugin=bin/protoc-gen-purescript --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
15+```
16+then
1217```console
1318cd plugin
1419```