Skip to content

Commit

Permalink
Merge pull request #131 from dibenede/package-dist
Browse files Browse the repository at this point in the history
Zip package files for distribution
  • Loading branch information
dibenede authored Sep 7, 2022
2 parents 37c293c + 1c3302c commit cb8c3ab
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 33 deletions.
29 changes: 0 additions & 29 deletions BUILD

This file was deleted.

61 changes: 61 additions & 0 deletions BUILD.bazel
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.
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ http_archive(
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
5 changes: 1 addition & 4 deletions generator/BUILD → generator/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ cc_binary(
],
visibility = ["//visibility:public"],
deps = [
#"@com_google_absl//absl/base:core_headers",
#"@com_google_absl//absl/container:flat_hash_map",
#"@com_google_absl//absl/container:flat_hash_set",
#"@com_google_absl//absl/strings",
"@com_google_protobuf//:protobuf",
"@com_google_protobuf//:protoc_lib",
],
)

51 changes: 51 additions & 0 deletions protobuf_javascript_release.bzl
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,
)

0 comments on commit cb8c3ab

Please sign in to comment.