Skip to content

Commit 0068ad3

Browse files
committed
spago bundle instructions
1 parent 9ff469c commit 0068ad3

22 files changed

+94
-68
lines changed

.github/workflows/ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
name: CI
22
on:
33
push:
4-
branches: [master, dev]
54
pull_request:
6-
branches: [master]
75

86
jobs:
97
test:

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
# v4.5.0 2024-12-02
4+
35
- `spago@next` build system. Reorganized packages.
46

57
# v4.4.0 2024-10-15

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ programs which use code generated by __protobuf__. Refer to these
258258
for further examples of how to use the generated code.
259259

260260
1. The `protoc`
261-
[compiler plugin](https://github.com/xc-jp/purescript-protobuf/blob/master/plugin/src/ProtocPlugin/Main.purs).
261+
[compiler plugin](https://github.com/xc-jp/purescript-protobuf/blob/master/plugin/src/Main.purs).
262262
The code generator imports generated code. This program writes itself.
263263
2. The
264264
[unit test suite](https://github.com/xc-jp/purescript-protobuf/blob/master/library/test/Main.purs)

bin/protoc-gen-purescript

+1-1
Original file line numberDiff line numberDiff line change
@@ -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/Main/index.js'; main();"

conformance/README.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,38 @@
22

33
## Running the conformance test
44

5+
### Running with Nix
6+
57
From the top directory of this repo,
68

7-
```console
9+
```shell
810
nix run .#conformance
911
```
10-
or
11-
```console
12+
13+
### Running from output/
14+
15+
```shell
1216
cd conformance
17+
```
18+
```shell
1319
spago build
1420
```
15-
```console
21+
```shell
1622
conformance_test_runner --enforce_recommended bin/conformance-purescript
1723
```
1824

25+
### Running from bundled executable
26+
27+
```shell
28+
cd conformance
29+
```
30+
```shell
31+
spago bundle --platform=node --minify --bundle-type app --outfile conformance.mjs
32+
```
33+
```shell
34+
conformance_test_runner --enforce_recommended ./conformance.mjs
35+
```
36+
1937
## About the conformance test runner
2038

2139
[Conformance README](https://github.com/protocolbuffers/protobuf/tree/master/conformance)
@@ -27,9 +45,9 @@ The derivations in `nix/protobuf.nix` will build `protoc` and the
2745

2846
To generate the conformance `.purs` in the dev environment:
2947

30-
```console
48+
```shell
3149
protoc --purescript_out=./conformance/src/generated --proto_path=$(nix path-info .#protobuf)/conformance $(nix path-info .#protobuf)/conformance/conformance.proto
3250
```
33-
```console
51+
```shell
3452
protoc --purescript_out=./conformance/src/generated --proto_path=$(nix path-info .#protobuf)/src $(nix path-info .#protobuf)/src/google/protobuf/test_messages_proto3.proto
3553
```

flake.nix

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@
5151
buildPhase = ''
5252
spago build --purs-args '${prev.purescript-protobuf-library.src}/src/**/*.purs'
5353
'';
54-
# The bundled minified output is CommonJS, so we need to change the run script to run node with CommonJS?
55-
# spago build --purs-args '${prev.purescript-protobuf-library.src}/**/*.purs'
56-
# purs-backend-es bundle-app --no-build --platform node --minify --output-dir output --main ProtocPlugin.Main
57-
# spago bundle --offline --pure --platform node --bundle-type app --minify --module ProtocPlugin.Main --purs-args '${prev.purescript-protobuf-library.src}/**/*.purs'
5854
installPhase = "mkdir $out; cp -r output/* $out/";
5955
};
6056
})
@@ -71,7 +67,7 @@
7167
})
7268
(prev: final: {
7369
protoc-gen-purescript = prev.writeScriptBin "protoc-gen-purescript" ''
74-
${prev.nodejs}/bin/node --input-type=module -e "import {main} from '${final.purescript-protobuf-plugin}/ProtocPlugin.Main/index.js'; main();"
70+
${prev.nodejs}/bin/node --input-type=module -e "import {main} from '${final.purescript-protobuf-plugin}/Main/index.js'; main();"
7571
'';
7672
conformance-purescript = prev.writeScriptBin "conformance-purescript" ''
7773
#!/usr/bin/env bash

plugin/README.md

+48-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
11

22
# PureScript plugin for Protoc
33

4-
Build:
4+
## Build
55

6-
```
6+
```shell
77
spago build
88
```
99

10+
## Bundle and Run
11+
12+
```shell
13+
spago bundle --platform node --minify --bundle-type app --outfile protoc-gen-purescript.mjs
14+
```
15+
16+
```shell
17+
protoc --plugin=protoc-gen-purescript=./protoc-gen-purescript.mjs --purescript_out=. google/protobuf/timestamp.proto
18+
```
19+
20+
## Unit Tests
21+
22+
To test purescript-protobuf, run `nix develop` from the top level directory
23+
of the repo, then:
24+
25+
```shell
26+
protoc --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
27+
```
28+
29+
Or, for the bundled plugin, not the Nix store:
30+
31+
```shell
32+
protoc --plugin=protoc-gen-purescript=./protoc-gen-purescript.mjs --purescript_out=./test/Test/generated --proto_path ./test ./test/*.proto
33+
```
34+
35+
then
36+
37+
```shell
38+
spago test
39+
```
40+
41+
## Benchmarks
42+
43+
To run the benchmarks, run `nix develop` from the top level directory, then:
44+
45+
```console
46+
cd plugin
47+
```
48+
```console
49+
spago test --main Test.Bench
50+
```
51+
52+
53+
## Development
54+
1055
The funny thing about writing a `protoc` compiler plugin codec is that it
1156
bootstraps itself. We just have to write enough of the compiler plugin codec
1257
that it can handle the `plugin.proto` and `descriptor.proto` files, and
@@ -17,7 +62,7 @@ Then we can delete the hand-written code and generate code to replace it
1762
with this command.
1863

1964
```shell
20-
protoc --purescript_out=./plugin/src/ProtocPlugin google/protobuf/compiler/plugin.proto
65+
protoc --plugin=protoc-gen-purescript=./protoc-gen-purescript.mjs --purescript_out=./src google/protobuf/compiler/plugin.proto
2166
```
2267

2368
See

plugin/src/ProtocPlugin/Main.purs renamed to plugin/src/Main.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
-- | Entry point for the code-generating executable `protoc` plugin. See the
2-
-- | package README for instructions on how to run the code generator.
1+
-- | Entry point for the code-generating executable plugin `protoc-gen-purescript`.
2+
-- | See the package README for instructions on how to run the code generator.
33

4-
module ProtocPlugin.Main (main) where
4+
module Main (main) where
55

66
import Prelude
77

plugin/test/README.md

-36
Original file line numberDiff line numberDiff line change
@@ -1,37 +1 @@
11
# Unit Tests
2-
3-
`unittest_proto3_optional.proto` is copied from
4-
`$(dirname $(which protoc))/../src/google/protobuf/unittest_proto3_optional.proto`
5-
6-
To test purescript-protobuf, run `nix develop` from the top level directory
7-
of the repo, then:
8-
9-
```console
10-
protoc --purescript_out=./plugin/test/Test/generated ./plugin/test/*.proto
11-
```
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
17-
```console
18-
cd plugin
19-
```
20-
```console
21-
spago build
22-
```
23-
```console
24-
spago test
25-
```
26-
27-
# Benchmarks
28-
29-
To run the benchmarks, run `nix develop` from the top level directory, then:
30-
31-
```console
32-
cd plugin
33-
```
34-
```console
35-
spago test --main Test.Bench
36-
```
37-

plugin/test/Test/generated/msg1.Pack.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg1.proto`
1+
-- | Generated by __protobuf__ from file `msg1.proto`
22
module Pack.Msg1
33
( Msg1(..), Msg1Row, Msg1R, parseMsg1, putMsg1, defaultMsg1, mkMsg1, mergeMsg1
44
, Msg1_E1(..)

plugin/test/Test/generated/msg2.Pack.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg2.proto`
1+
-- | Generated by __protobuf__ from file `msg2.proto`
22
module Pack.Msg2
33
( Msg2(..), Msg2Row, Msg2R, parseMsg2, putMsg2, defaultMsg2, mkMsg2, mergeMsg2
44
, Msg2_E1(..)

plugin/test/Test/generated/msg3.Pack3.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg3.proto`
1+
-- | Generated by __protobuf__ from file `msg3.proto`
22
module Pack3.Msg3
33
( Msg3(..), Msg3Row, Msg3R, parseMsg3, putMsg3, defaultMsg3, mkMsg3, mergeMsg3
44
, Msg3_Msg4(..), Msg3_Msg4Row, Msg3_Msg4R, parseMsg3_Msg4, putMsg3_Msg4, defaultMsg3_Msg4, mkMsg3_Msg4, mergeMsg3_Msg4

plugin/test/Test/generated/msg4.Pack4.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg4.proto`
1+
-- | Generated by __protobuf__ from file `msg4.proto`
22
module Pack4.Msg4
33
( Msg2(..), Msg2Row, Msg2R, parseMsg2, putMsg2, defaultMsg2, mkMsg2, mergeMsg2
44
, Msg1(..), Msg1Row, Msg1R, parseMsg1, putMsg1, defaultMsg1, mkMsg1, mergeMsg1

plugin/test/Test/generated/msg5.Pack5.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg5.proto`
1+
-- | Generated by __protobuf__ from file `msg5.proto`
22
module Pack5.Msg5
33
( Msg1(..), Msg1Row, Msg1R, parseMsg1, putMsg1, defaultMsg1, mkMsg1, mergeMsg1, Msg1_Sum1(..)
44
, Msg2(..), Msg2Row, Msg2R, parseMsg2, putMsg2, defaultMsg2, mkMsg2, mergeMsg2, Msg2_Sum1(..)

plugin/test/Test/generated/msg5_1.Pack5.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg5_1.proto`
1+
-- | Generated by __protobuf__ from file `msg5_1.proto`
22
module Pack5.Msg51
33
( Msg2(..), Msg2Row, Msg2R, parseMsg2, putMsg2, defaultMsg2, mkMsg2, mergeMsg2
44
)

plugin/test/Test/generated/msg6.Pack6.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg6.proto`
1+
-- | Generated by __protobuf__ from file `msg6.proto`
22
module Pack6.Msg6
33
( Msg6(..), Msg6Row, Msg6R, parseMsg6, putMsg6, defaultMsg6, mkMsg6, mergeMsg6
44
)

plugin/test/Test/generated/msg7.Pack7.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
-- | Generated by __protobuf__ from file `plugin/test/msg7.proto`
1+
-- | Generated by __protobuf__ from file `msg7.proto`
22
module Pack7.Msg7
33
( Msg7(..), Msg7Row, Msg7R, parseMsg7, putMsg7, defaultMsg7, mkMsg7, mergeMsg7
44
)

plugin/test/msg3.proto

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ syntax = "proto3";
22

33
package pack3;
44

5-
import "plugin/test/msg1.proto";
6-
import "plugin/test/msg2.proto";
5+
import "msg1.proto";
6+
import "msg2.proto";
77

88
message msg3 {
99
repeated pack.msg1 f1 = 1;

plugin/test/msg5_1.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ syntax = "proto3";
22

33
package pack5;
44

5-
import "plugin/test/msg5.proto";
5+
import "msg5.proto";
66

77
message Msg2 {
88
Msg1 f1 = 1;

plugin/test/msg6.proto

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ syntax = "proto3";
22

33
package pack6;
44

5+
// `unittest_proto3_optional.proto` is copied from
6+
// `$(dirname $(which protoc))/../src/google/protobuf/unittest_proto3_optional.proto`
7+
58
// import "google/protobuf/unittest_proto3_optional.proto";
69

710
message Msg6 {

0 commit comments

Comments
 (0)