-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from dibenede/package-dist
Zip package files for distribution
- Loading branch information
Showing
6 changed files
with
116 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Protobuf JS runtime | ||
# | ||
# See also code generation logic under generator/ | ||
|
||
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") | ||
|
||
package_naming( | ||
name = "protobuf_javascript_pkg_naming", | ||
) | ||
|
||
pkg_files( | ||
name = "plugin_files", | ||
srcs = ["//generator:protoc-gen-js"], | ||
attributes = pkg_attributes(mode = "0555"), | ||
prefix = "bin/", | ||
) | ||
|
||
pkg_files( | ||
name = "dist_files", | ||
srcs = glob([ | ||
"google/protobuf/*.js", | ||
"google/protobuf/compiler/*.js" | ||
]) + [ | ||
"google-protobuf.js", | ||
"package.json", | ||
"README.md", | ||
"LICENSE.md", | ||
], | ||
strip_prefix = strip_prefix.from_root(""), | ||
) | ||
|
||
pkg_tar( | ||
name = "dist_tar", | ||
srcs = [ | ||
":dist_files", | ||
":plugin_files", | ||
], | ||
extension = "tar.gz", | ||
package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz", | ||
package_variables = ":protobuf_javascript_pkg_naming", | ||
) | ||
|
||
pkg_zip( | ||
name = "dist_zip", | ||
srcs = [ | ||
":dist_files", | ||
":plugin_files", | ||
], | ||
package_file_name = "protobuf-javascript-{version}-{platform}.zip", | ||
package_variables = ":protobuf_javascript_pkg_naming", | ||
) | ||
|
||
filegroup( | ||
name = "dist_all", | ||
srcs = [ | ||
":dist_tar", | ||
":dist_zip", | ||
] | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Generates package naming variables for use with rules_pkg. | ||
""" | ||
|
||
load("@rules_pkg//:providers.bzl", "PackageVariablesInfo") | ||
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain") | ||
|
||
_PROTOBUF_JAVASCRIPT_VERSION = '3.21.0' | ||
|
||
def _package_naming_impl(ctx): | ||
values = {} | ||
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION | ||
|
||
# infer from the current cpp toolchain. | ||
toolchain = find_cpp_toolchain(ctx) | ||
cpu = toolchain.cpu | ||
system_name = toolchain.target_gnu_system_name | ||
|
||
# rename cpus to match what we want artifacts to be | ||
if cpu == "systemz": | ||
cpu = "s390_64" | ||
elif cpu == "aarch64": | ||
cpu = "aarch_64" | ||
elif cpu == "ppc64": | ||
cpu = "ppcle_64" | ||
|
||
# use the system name to determine the os and then create platform names | ||
if "apple" in system_name: | ||
values["platform"] = "osx-" + cpu | ||
elif "linux" in system_name: | ||
values["platform"] = "linux-" + cpu | ||
elif "mingw" in system_name: | ||
if cpu == "x86_64": | ||
values["platform"] = "win64" | ||
else: | ||
values["platform"] = "win32" | ||
else: | ||
values["platform"] = "unknown" | ||
|
||
return PackageVariablesInfo(values = values) | ||
|
||
|
||
package_naming = rule( | ||
implementation = _package_naming_impl, | ||
attrs = { | ||
# Necessary data dependency for find_cpp_toolchain. | ||
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), | ||
}, | ||
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"], | ||
incompatible_use_toolchain_transition = True, | ||
) |