Skip to content

Commit 1c3302c

Browse files
committed
Zip package files for distribution
* Rename BUILD -> BUILD.bazel, which is the preferred naming scheme. * Remove tests (especially old conformance tests) and test data from distribution. * Add license file zip package files for distribution
1 parent a428c58 commit 1c3302c

File tree

6 files changed

+116
-33
lines changed

6 files changed

+116
-33
lines changed

BUILD

-29
This file was deleted.

BUILD.bazel

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Protobuf JS runtime
2+
#
3+
# See also code generation logic under generator/
4+
5+
load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
6+
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
7+
load("//:protobuf_javascript_release.bzl", "package_naming")
8+
9+
package_naming(
10+
name = "protobuf_javascript_pkg_naming",
11+
)
12+
13+
pkg_files(
14+
name = "plugin_files",
15+
srcs = ["//generator:protoc-gen-js"],
16+
attributes = pkg_attributes(mode = "0555"),
17+
prefix = "bin/",
18+
)
19+
20+
pkg_files(
21+
name = "dist_files",
22+
srcs = glob([
23+
"google/protobuf/*.js",
24+
"google/protobuf/compiler/*.js"
25+
]) + [
26+
"google-protobuf.js",
27+
"package.json",
28+
"README.md",
29+
"LICENSE.md",
30+
],
31+
strip_prefix = strip_prefix.from_root(""),
32+
)
33+
34+
pkg_tar(
35+
name = "dist_tar",
36+
srcs = [
37+
":dist_files",
38+
":plugin_files",
39+
],
40+
extension = "tar.gz",
41+
package_file_name = "protobuf-javascript-{version}-{platform}.tar.gz",
42+
package_variables = ":protobuf_javascript_pkg_naming",
43+
)
44+
45+
pkg_zip(
46+
name = "dist_zip",
47+
srcs = [
48+
":dist_files",
49+
":plugin_files",
50+
],
51+
package_file_name = "protobuf-javascript-{version}-{platform}.zip",
52+
package_variables = ":protobuf_javascript_pkg_naming",
53+
)
54+
55+
filegroup(
56+
name = "dist_all",
57+
srcs = [
58+
":dist_tar",
59+
":dist_zip",
60+
]
61+
)

LICENSE renamed to LICENSE.md

File renamed without changes.

WORKSPACE

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ http_archive(
1111
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
1212

1313
protobuf_deps()
14+
15+
load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
16+
rules_pkg_dependencies()

generator/BUILD renamed to generator/BUILD.bazel

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ cc_binary(
99
],
1010
visibility = ["//visibility:public"],
1111
deps = [
12-
#"@com_google_absl//absl/base:core_headers",
13-
#"@com_google_absl//absl/container:flat_hash_map",
14-
#"@com_google_absl//absl/container:flat_hash_set",
15-
#"@com_google_absl//absl/strings",
1612
"@com_google_protobuf//:protobuf",
1713
"@com_google_protobuf//:protoc_lib",
1814
],
1915
)
16+

protobuf_javascript_release.bzl

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Generates package naming variables for use with rules_pkg.
3+
"""
4+
5+
load("@rules_pkg//:providers.bzl", "PackageVariablesInfo")
6+
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
7+
8+
_PROTOBUF_JAVASCRIPT_VERSION = '3.21.0'
9+
10+
def _package_naming_impl(ctx):
11+
values = {}
12+
values["version"] = _PROTOBUF_JAVASCRIPT_VERSION
13+
14+
# infer from the current cpp toolchain.
15+
toolchain = find_cpp_toolchain(ctx)
16+
cpu = toolchain.cpu
17+
system_name = toolchain.target_gnu_system_name
18+
19+
# rename cpus to match what we want artifacts to be
20+
if cpu == "systemz":
21+
cpu = "s390_64"
22+
elif cpu == "aarch64":
23+
cpu = "aarch_64"
24+
elif cpu == "ppc64":
25+
cpu = "ppcle_64"
26+
27+
# use the system name to determine the os and then create platform names
28+
if "apple" in system_name:
29+
values["platform"] = "osx-" + cpu
30+
elif "linux" in system_name:
31+
values["platform"] = "linux-" + cpu
32+
elif "mingw" in system_name:
33+
if cpu == "x86_64":
34+
values["platform"] = "win64"
35+
else:
36+
values["platform"] = "win32"
37+
else:
38+
values["platform"] = "unknown"
39+
40+
return PackageVariablesInfo(values = values)
41+
42+
43+
package_naming = rule(
44+
implementation = _package_naming_impl,
45+
attrs = {
46+
# Necessary data dependency for find_cpp_toolchain.
47+
"_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")),
48+
},
49+
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
50+
incompatible_use_toolchain_transition = True,
51+
)

0 commit comments

Comments
 (0)