Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to spago@next #40

Merged
merged 10 commits into from
Dec 2, 2024
Merged
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
62 changes: 42 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,70 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
# https://github.com/marketplace/actions/cache-apt-packages
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: protobuf-compiler

# https://github.com/purescript-contrib/setup-purescript/
- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purescript: "unstable"
purs-tidy: "latest"
spago: "unstable"

# https://github.com/marketplace/actions/cache
- name: Cache PureScript dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}-2
key: ${{ runner.os }}-spago-${{ hashFiles('**/spago.lock') }}-2
path: |
.spago
output
./plugin/.spago
./conformance/.spago

- name: Install dependencies
run: spago install
run: |
protoc --version
echo -n "node "
node --version
echo -n "purs "
purs --version
echo -n "spago "
spago --version
echo ""
spago install

- name: Install plugin dependencies
run: spago -x spago-plugin.dhall install
- name: Build Plugin
run: |
cd plugin
spago build

- name: Install test dependencies
run: spago -x spago-test.dhall install
- name: Test Plugin
# Need --experimental_allow_proto3_optional until the CI protoc is upgraded
run: |
protoc --experimental_allow_proto3_optional --plugin=bin/protoc-gen-purescript --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
cd plugin
spago test

- name: Build plugin
run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''
# - name: Install test dependencies
# run: spago -x spago-test.dhall install

- run: mkdir -p ./test/generated
# - name: Build plugin
# run: spago -x spago-plugin.dhall build --no-install --purs-args '--censor-lib --strict --censor-codes='UserDefinedWarning''

- name: Generate test from .proto
run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto
# - run: mkdir -p ./test/generated

- name: Build test
run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''
# - name: Generate test from .proto
# run: PATH=./bin:$PATH protoc --experimental_allow_proto3_optional --purescript_out=./test/generated test/*.proto

- name: Run tests
run: spago -x spago-test.dhall test --no-install
# - name: Build test
# run: spago -x spago-test.dhall build --no-install --purs-args '--censor-lib --censor-codes='UserDefinedWarning''

# - name: Run tests
# run: spago -x spago-test.dhall test --no-install

# We're not running the conformance test because the conformance
# test runner is a pretty heavy build.
# test runner is a pretty heavy build.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"purescript.buildCommand": "spago -x spago-dev.dhall build --purs-args --json-errors",
"purescript.buildCommand": "spago build --json-errors",
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

- `spago@next` build system. Reorganized packages.

# v4.4.0 2024-10-15

Expand Down
67 changes: 45 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ We do not support

### Conformance and Testing

In this version, we pass all 651 of the
In this version, we pass all 684 of the
[Google conformance tests](https://github.com/protocolbuffers/protobuf/tree/main/conformance)
of binary-wire-format *proto3* for [Protocol Buffers v23.2](https://github.com/protocolbuffers/protobuf/releases/).
of binary-wire-format *proto3* for [Protocol Buffers v28.2](https://github.com/protocolbuffers/protobuf/releases/tag/v28.2).
See the `conformance/README.md` in this repository for details.

We also have our own unit tests, see `test/README.md` in this repository.
Expand All @@ -50,13 +50,15 @@ The `nix develop` environment provides
$ nix develop

PureScript Protobuf development environment
libprotoc 23.2
purs 0.15.8
node v18.16.0
libprotoc 28.2
node v20.15.1
purs 0.15.15
spago 0.93.40

To build the protoc compiler plugin, run:

spago -x spago-plugin.dhall build
cd plugin
spago build

To compile PureScript .purs files from .proto files, run for example:

Expand All @@ -65,19 +67,30 @@ To compile PureScript .purs files from .proto files, run for example:

We can test out code generation immediately by
generating `.purs` files for any of Google’s built-in “well-known types” in the
[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command `protoc --purescript_out=. google/protobuf/any.proto`
or `protoc --purescript_out=. google/protobuf/timestamp.proto`.
[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command
```console
protoc --purescript_out=. google/protobuf/any.proto
```
or
```console
protoc --purescript_out=. google/protobuf/timestamp.proto
```

To see
[all of the `.proto` definitions](https://github.com/protocolbuffers/protobuf/tree/main/src/google/protobuf)
included with the Nix PureScript Protobuf installation including
the “well-known types,”
`ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto`
```console
ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto
```

If you don't want to use Nix, then install the PureScript toolchain and `protoc`,
and add the executable script
[`bin/protoc-gen-purescript`](bin/protoc-gen-purescript)
to your `PATH`.
If you don't want to use Nix,
1. install the PureScript toolchain and `protoc`.
2. Build the [PureScript plugin for `protoc`](plugin/).
3. Run `protoc` with the path to the PureScript plugin executable, like for example
```console
protoc --plugin=bin/protoc-gen-purescript --purescript_out=. google/protobuf/timestamp.proto
```

## Writing programs with the generated code

Expand Down Expand Up @@ -245,13 +258,12 @@ programs which use code generated by __protobuf__. Refer to these
for further examples of how to use the generated code.

1. The `protoc`
[compiler plugin](https://github.com/xc-jp/purescript-protobuf/blob/master/plugin/ProtocPlugin/Main.purs).
The code generator imports generated code. Trippy, right? This program
literally writes itself.
[compiler plugin](https://github.com/xc-jp/purescript-protobuf/blob/master/plugin/src/ProtocPlugin/Main.purs).
The code generator imports generated code. This program writes itself.
2. The
[unit test suite](https://github.com/xc-jp/purescript-protobuf/blob/master/test/Main.purs)
[unit test suite](https://github.com/xc-jp/purescript-protobuf/blob/master/library/test/Main.purs)
3. The Google
[conformance test program](https://github.com/xc-jp/purescript-protobuf/blob/master/conformance/Main.purs)
[conformance test program](https://github.com/xc-jp/purescript-protobuf/blob/master/conformance/src/Main.purs)

The [Protobuf Decoder Explainer](http://jamesdbrock.github.io/protobuf-decoder-explainer/) shows an
example of how to use this library to parse binary Protobuf when we don’t
Expand Down Expand Up @@ -317,10 +329,11 @@ For that reason, we can only use top-level
### PureScript Imports

The generated PureScript code will usually have module imports which cause
the `purs` compiler to emit redundant import warnings. Sorry. If this causes
the `purs` compiler to emit `ImplicitQualifiedImport` warnings. Sorry. If this causes
trouble then the imports can be fixed automatically in a precompiling pass
with the command-line tool
[__suggest__](https://github.com/nwolverson/purescript-suggest).
Or you can [censor the warnings](https://discourse.purescript.org/t/suppressing-warnings-in-code/2485).

## Nix derivation

Expand All @@ -330,9 +343,19 @@ derivation. Include `protoc-gen-purescript` and `protobuf` as `nativeBuildInputs
Then `protoc --purescript_out=path_to_output file.proto` will be runnable
in our derivation phases.

(`protoc-gen-purescript` requires an impure build for the `spago2nix` step,
so you’ll have to grant
trust at the prompt or configure a relaxed Nix sandbox.)
Building `protoc-gen-purescript` requires an impure Nix build environment.

You might need in your `flake.nix`:

```
nixConfig.sandbox = "relaxed";
```

You might need in your `~/.config/nix.conf`:

```
experimental-features = nix-command flakes configurable-impure-env auto-allocate-uids
```

The `flake.nix` provides the Google Protocol Buffers conformance tests
as an `app`. To run the conformance tests right now
Expand Down
2 changes: 1 addition & 1 deletion bin/conformance-purescript
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
node --input-type=module -e "import {main} from './output/Conformance.Main/index.js'; main();"
node --input-type=module --abort-on-uncaught-exception --trace-sigint --trace-uncaught -e "import {main} from './conformance/output/Main/index.js'; main();"
2 changes: 1 addition & 1 deletion bin/protoc-gen-purescript
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
node --input-type=module -e "import {main} from './output/ProtocPlugin.Main/index.js'; main();"
node --input-type=module -e "import {main} from './plugin/output/ProtocPlugin.Main/index.js'; main();"
44 changes: 0 additions & 44 deletions bower.json

This file was deleted.

12 changes: 10 additions & 2 deletions conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ From the top directory of this repo,
```console
nix run .#conformance
```
or
```console
cd conformance
spago build
```
```console
conformance_test_runner --enforce_recommended bin/conformance-purescript
```

## About the conformance test runner

Expand All @@ -20,8 +28,8 @@ The derivations in `nix/protobuf.nix` will build `protoc` and the
To generate the conformance `.purs` in the dev environment:

```console
protoc --purescript_out=./conformance/generated --proto_path=$(nix path-info .#protobuf)/conformance $(nix path-info .#protobuf)/conformance/conformance.proto
protoc --purescript_out=./conformance/src/generated --proto_path=$(nix path-info .#protobuf)/conformance $(nix path-info .#protobuf)/conformance/conformance.proto
```
```console
protoc --purescript_out=./conformance/generated --proto_path=$(nix path-info .#protobuf)/src $(nix path-info .#protobuf)/src/google/protobuf/test_messages_proto3.proto
protoc --purescript_out=./conformance/src/generated --proto_path=$(nix path-info .#protobuf)/src $(nix path-info .#protobuf)/src/google/protobuf/test_messages_proto3.proto
```
1 change: 0 additions & 1 deletion conformance/generated/.gitignore

This file was deleted.

Loading