Skip to content

Windows 32/64 Github Action Builds #166

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

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .github/actions/setup-protoc-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Setup the protoc environment'
description: 'Setup the protoc environment with the right PROTOC and PROTOC_INC environment variables'
runs:
using: 'node16'
main: 'index.js'
22 changes: 22 additions & 0 deletions .github/actions/setup-protoc-env/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const tc = require('@actions/tool-cache');
const core = require('@actions/core');
const os = require('os');
const path = require('path');

const versions = tc.findAllVersions('protoc');
if (versions.length === 0)
throw new Error('Unable to find protoc tool version');

const version = versions[0];
const toolPath = tc.find('protoc', version).replaceAll(path.win32.sep, path.posix.sep);
const protocExec = os.platform() === 'win32' ? 'protoc.exe' : 'protoc';

// need to use posix paths
const protocPath = path.posix.join(toolPath, 'bin', protocExec);
const protocIncPath = path.posix.join(toolPath, 'include');

console.log("protoc path:", protocPath);
console.log("protoc include path:", protocIncPath);

core.exportVariable('PROTOC', protocPath);
core.exportVariable('PROTOC_INC', protocIncPath);
102 changes: 102 additions & 0 deletions .github/actions/setup-protoc-env/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .github/actions/setup-protoc-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "setup-protoc-env",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"private": true,
"license": "BSD-3-Clause",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/tool-cache": "^2.0.1"
},
"devDependencies": {
"@types/node": "^16.18.14"
}
}
66 changes: 66 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Windows Build

on:
push:
tags: [ "*" ]

jobs:
build:
runs-on: windows-latest

steps:
- uses: actions/checkout@v3

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
cache-dependency-path: |
package-lock.json
.github/actions/setup-protoc-env/package-lock.json

- name: Setup Bazelisk
uses: bazelbuild/setup-bazelisk@v2

- name: Mount bazel cache
uses: actions/cache@v3
with:
path: "~/.cache/bazel"
key: bazel

- name: Install protoc
uses: arduino/setup-protoc@v1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use this for security reasons. Can you do something like this instead?

https://github.com/protocolbuffers/protobuf-javascript/blob/main/.github/workflows/codeql.yml#L61-L68

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. That will probably make it so I can completely skip the custom action but I'll see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now completely removed the arduino/setup-protoc dep and standardized the download of the protoc executable/includes between build.yml and codeql.yml

Should you want to update the version, you can now just copy and paste the top environment variable between the two files easily.

This also simplified the actual codeql.yml config as well into separate steps.


- run: npm ci --omit=dev
working-directory: .github/actions/setup-protoc-env

- name: Setup protoc environment
uses: ./.github/actions/setup-protoc-env

- run: npm ci

- run: npm run build
shell: bash

- name: Package (x64)
run: bazel build --cpu=x64_windows dist_zip
shell: bash

- name: Copy (x64)
run: |
mkdir out
cp bazel-bin/protobuf-javascript-*.zip out/

- name: Package (x86)
run: bazel build --cpu=x64_x86_windows dist_zip
shell: bash

- name: Copy (x86)
run: |
cp bazel-bin/protobuf-javascript-*.zip out/

- name: Release
uses: softprops/action-gh-release@v1
with:
files: "out/*.zip"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.idea
/node_modules/
node_modules
commonjs_out
google/protobuf
bazel-*
Expand Down
15 changes: 15 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@ load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load("//:protobuf_javascript_release.bzl", "package_naming")

config_setting(
name = "x64_x86_windows",
values = {"cpu": "x64_x86_windows"},
)

config_setting(
name = "x64_windows",
values = {"cpu": "x64_windows"},
)

package_naming(
name = "protobuf_javascript_pkg_naming",
platform = select({
":x64_x86_windows": "win32",
":x64_windows": "win64",
"//conditions:default": ""
})
)

pkg_files(
Expand Down
5 changes: 5 additions & 0 deletions protobuf_javascript_release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def _package_naming_impl(ctx):
values = {}
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION

if ctx.attr.platform != "":
values["platform"] = ctx.attr.platform
return PackageVariablesInfo(values=values)

# infer from the current cpp toolchain.
toolchain = find_cpp_toolchain(ctx)
cpu = toolchain.cpu
Expand Down Expand Up @@ -46,6 +50,7 @@ package_naming = rule(
"_cc_toolchain":
attr.label(
default=Label("@bazel_tools//tools/cpp:current_cc_toolchain"),),
"platform": attr.string(),
},
toolchains=["@bazel_tools//tools/cpp:toolchain_type"],
incompatible_use_toolchain_transition=True,
Expand Down