Skip to content

Commit

Permalink
Use buf instead of protoc to compile protobufs (#146)
Browse files Browse the repository at this point in the history
This is more consistent with the embedded host, and avoids relying on
the seldom-maintaned arduino/setup-protoc GitHub action.
  • Loading branch information
nex3 authored Feb 9, 2023
1 parent 487753e commit f50a3f0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
43 changes: 15 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: CI
defaults:
run: {shell: bash}

env:
protoc_version: '3.x'

on:
push:
branches: [main, feature.*]
Expand All @@ -28,8 +25,8 @@ jobs:
- uses: actions/checkout@v3
- uses: frenck/action-setup-yq@v1
with: {version: v4.30.5} # frenck/action-setup-yq#35
- uses: arduino/setup-protoc@v1
with: { version: "${{ env.protoc_version }}", repo-token: "${{ github.token }}" }
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}
- uses: dart-lang/setup-dart@v1
with: {sdk: "${{ matrix.dart_channel }}"}

Expand Down Expand Up @@ -86,10 +83,8 @@ jobs:
with: {sdk: stable}
- uses: frenck/action-setup-yq@v1
with: {version: v4.30.5} # frenck/action-setup-yq#35
- uses: arduino/setup-protoc@v1
with:
version: ${{ env.PROTOC_VERSION }}
repo-token: '${{ github.token }}'
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}

- name: Check out Dart Sass only if linked in the PR description
uses: sass/clone-linked-repo@v1
Expand Down Expand Up @@ -161,8 +156,8 @@ jobs:
- uses: actions/checkout@v3
- uses: frenck/action-setup-yq@v1
with: {version: v4.30.5} # frenck/action-setup-yq#35
- uses: arduino/setup-protoc@v1
with: { version: "${{ env.protoc_version }}", repo-token: "${{ github.token }}" }
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}
- uses: dart-lang/setup-dart@v1

- name: Check out Dart Sass only if linked in the PR description
Expand Down Expand Up @@ -210,20 +205,11 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: arduino/setup-protoc@v1
with: { version: "${{ env.protoc_version }}", repo-token: "${{ github.token }}" }
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}
- uses: dart-lang/setup-dart@v1
- run: dart pub get
- run: dart run grinder protobuf
# We need to upload the compiled protobuf rather than recompiling it on
# other platforms because arduino/setup-protoc currently) requires Node 12
# which doesn't support ARM.
- uses: actions/upload-artifact@v3
with:
name: embedded-protocol
path: |
build/embedded-protocol
lib/src/embedded_sass.*.dart
- name: Deploy
run: dart run grinder pkg-github-release pkg-github-linux-ia32 pkg-github-linux-x64
env: {GH_BEARER_TOKEN: "${{ github.token }}"}
Expand All @@ -243,9 +229,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: embedded-protocol
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}
- run: dart pub get
- run: dart pub grinder protobuf
- uses: docker/setup-qemu-action@v2
- name: Deploy
run: |
Expand Down Expand Up @@ -278,14 +265,14 @@ jobs:

steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: embedded-protocol
- uses: bufbuild/buf-setup-action@v1.13.1
with: {github_token: "${{ github.token }}"}
- uses: dart-lang/setup-dart@v1
# Workaround for dart-lang/setup-dart#59
with:
architecture: ${{ matrix.architecture }}
- run: dart pub get
- run: dart pub run grinder protobuf
- name: Deploy
run: dart run grinder pkg-github-${{ matrix.platform }}
env: {GH_BEARER_TOKEN: "${{ github.token }}"}
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ and importers.
- `dart-sass-embedded` starts the compiler and listens on stdin.
- `dart-sass-embedded --version` prints `versionResponse` with `id = 0` in JSON and exits.

### Development

To run the embedded compiler from source:

* Run `dart pub get`.

* [Install `buf`].

* Run `dart run grinder protobuf`.

From there, you can either run `dart bin/dart_sass_embedded.dart` directly or
`dart run grinder pkg-standalone-dev` to build a compiled development
executable.

[Install `buf`]: https://docs.buf.build/installation

### Releases

Binary releases are available from the [GitHub release page]. We recommend that
Expand Down
4 changes: 4 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: v1
plugins:
- plugin: dart
out: lib/src
2 changes: 2 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version: v1
directories: [build/embedded-protocol]
16 changes: 7 additions & 9 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,22 @@ Future<void> protobuf() async {
if (Platform.isWindows) {
File('build/protoc-gen-dart.bat').writeAsStringSync('''
@echo off
dart pub run protoc_plugin %*
dart run protoc_plugin %*
''');
} else {
File('build/protoc-gen-dart')
.writeAsStringSync('dart pub run protoc_plugin "\$@"');
File('build/protoc-gen-dart').writeAsStringSync('''
#!/bin/sh
dart run protoc_plugin "\$@"
''');
run('chmod', arguments: ['a+x', 'build/protoc-gen-dart']);
}

if (Platform.environment['UPDATE_SASS_PROTOCOL'] != 'false') {
await cloneOrPull("https://github.com/sass/embedded-protocol.git");
}

await runAsync("protoc",
arguments: [
"-Ibuild/embedded-protocol",
"embedded_sass.proto",
"--dart_out=lib/src/"
],
await runAsync("buf",
arguments: ["generate"],
runOptions: RunOptions(environment: {
"PATH": 'build' +
(Platform.isWindows ? ";" : ":") +
Expand Down

0 comments on commit f50a3f0

Please sign in to comment.