diff --git a/BUILD b/BUILD deleted file mode 100644 index ea37196..0000000 --- a/BUILD +++ /dev/null @@ -1,29 +0,0 @@ -# Protobuf JS runtime -# -# See also code generation logic under compiler/ - -load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix") - -pkg_files( - name = "dist_files", - srcs = glob([ - "*.js", - "*.json", - "*.proto", - "binary/*.js", - "commonjs/*.js*", # js, json - "commonjs/**/*.proto", - "compatibility_tests/v3.0.0/**/*.js*", - "compatibility_tests/v3.0.0/**/*.proto", - "compatibility_tests/v3.0.0/**/*.sh", - "compatibility_tests/v3.1.0/**/*.js*", - "compatibility_tests/v3.1.0/**/*.proto", - "experimental/benchmarks/**/*.js", - "experimental/runtime/**/*.js", - ]) + [ - "BUILD", - "README.md", - ], - strip_prefix = strip_prefix.from_root(""), - visibility = ["//pkg:__pkg__"], -) diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..2b4b0e3 --- /dev/null +++ b/BUILD.bazel @@ -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", + ] +) diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/WORKSPACE b/WORKSPACE index 98e345e..9a4a54a 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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() diff --git a/generator/BUILD b/generator/BUILD.bazel similarity index 63% rename from generator/BUILD rename to generator/BUILD.bazel index de1fc18..b865ca4 100644 --- a/generator/BUILD +++ b/generator/BUILD.bazel @@ -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", ], ) + diff --git a/protobuf_javascript_release.bzl b/protobuf_javascript_release.bzl new file mode 100644 index 0000000..c462e99 --- /dev/null +++ b/protobuf_javascript_release.bzl @@ -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, +) \ No newline at end of file