build: add manifest.json to Bazel build

Bug: twpowertools:255
Change-Id: I6a6a69649e6eda17d83194f19fcf43e774a95c70
diff --git a/MODULE.bazel b/MODULE.bazel
index 0efb6ed..6c49064 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -3,6 +3,7 @@
 bazel_dep(name = "aspect_rules_webpack", version = "0.17.1")
 bazel_dep(name = "bazel_skylib", version = "1.8.1")
 bazel_dep(name = "gazelle", version = "0.45.0")
+bazel_dep(name = "rules_go", version = "0.57.0")
 bazel_dep(name = "rules_nodejs", version = "6.5.0")
 bazel_dep(name = "rules_pkg", version = "1.1.0")
 
@@ -22,3 +23,7 @@
 # Allows developers to use the matching pnpm version, for example:
 # bazel run -- @pnpm --dir /path/to/infinitegforums install
 use_repo(pnpm, "pnpm")
+
+go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
+go_deps.from_file(go_mod = "//:go.mod")
+use_repo(go_deps, "com_avm99963_gomodules_webext")
diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock
index aa1dbeb..402f146 100644
--- a/MODULE.bazel.lock
+++ b/MODULE.bazel.lock
@@ -75,15 +75,17 @@
     "https://bcr.bazel.build/modules/package_metadata/0.0.5/source.json": "2326db2f6592578177751c3e1f74786b79382cd6008834c9d01ec865b9126a85",
     "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5",
     "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f",
-    "https://bcr.bazel.build/modules/platforms/0.0.11/source.json": "f7e188b79ebedebfe75e9e1d098b8845226c7992b307e28e1496f23112e8fc29",
     "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee",
     "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37",
     "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615",
     "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814",
     "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d",
+    "https://bcr.bazel.build/modules/platforms/1.0.0/MODULE.bazel": "f05feb42b48f1b3c225e4ccf351f367be0371411a803198ec34a389fb22aa580",
+    "https://bcr.bazel.build/modules/platforms/1.0.0/source.json": "f4ff1fd412e0246fd38c82328eb209130ead81d62dcd5a9e40910f867f733d96",
     "https://bcr.bazel.build/modules/protobuf/21.7/MODULE.bazel": "a5a29bb89544f9b97edce05642fac225a808b5b7be74038ea3640fae2f8e66a7",
     "https://bcr.bazel.build/modules/protobuf/27.0/MODULE.bazel": "7873b60be88844a0a1d8f80b9d5d20cfbd8495a689b8763e76c6372998d3f64c",
     "https://bcr.bazel.build/modules/protobuf/27.1/MODULE.bazel": "703a7b614728bb06647f965264967a8ef1c39e09e8f167b3ca0bb1fd80449c0d",
+    "https://bcr.bazel.build/modules/protobuf/29.0-rc2.bcr.1/MODULE.bazel": "52f4126f63a2f0bbf36b99c2a87648f08467a4eaf92ba726bc7d6a500bbf770c",
     "https://bcr.bazel.build/modules/protobuf/29.0-rc2/MODULE.bazel": "6241d35983510143049943fc0d57937937122baf1b287862f9dc8590fc4c37df",
     "https://bcr.bazel.build/modules/protobuf/29.0-rc3/MODULE.bazel": "33c2dfa286578573afc55a7acaea3cada4122b9631007c594bf0729f41c8de92",
     "https://bcr.bazel.build/modules/protobuf/29.0/MODULE.bazel": "319dc8bf4c679ff87e71b1ccfb5a6e90a6dbc4693501d471f48662ac46d04e4e",
@@ -117,7 +119,8 @@
     "https://bcr.bazel.build/modules/rules_go/0.42.0/MODULE.bazel": "8cfa875b9aa8c6fce2b2e5925e73c1388173ea3c32a0db4d2b4804b453c14270",
     "https://bcr.bazel.build/modules/rules_go/0.46.0/MODULE.bazel": "3477df8bdcc49e698b9d25f734c4f3a9f5931ff34ee48a2c662be168f5f2d3fd",
     "https://bcr.bazel.build/modules/rules_go/0.53.0/MODULE.bazel": "a4ed760d3ac0dbc0d7b967631a9a3fd9100d28f7d9fcf214b4df87d4bfff5f9a",
-    "https://bcr.bazel.build/modules/rules_go/0.53.0/source.json": "c6dc34fb5bb8838652221a167d8f35ca3c8fdcbff8568f13cc75719802f95cff",
+    "https://bcr.bazel.build/modules/rules_go/0.57.0/MODULE.bazel": "bee44028b527cd6d1b7699a2c78714bba237b40ee21f90a83b472c94bc53159d",
+    "https://bcr.bazel.build/modules/rules_go/0.57.0/source.json": "a782b756d87c68a223a48848eda4b0dac1c5fd1d925d648d7598b68aa1fb6d6d",
     "https://bcr.bazel.build/modules/rules_java/4.0.0/MODULE.bazel": "5a78a7ae82cd1a33cef56dc578c7d2a46ed0dca12643ee45edbb8417899e6f74",
     "https://bcr.bazel.build/modules/rules_java/5.3.5/MODULE.bazel": "a4ec4f2db570171e3e5eb753276ee4b389bae16b96207e9d3230895c99644b86",
     "https://bcr.bazel.build/modules/rules_java/6.0.0/MODULE.bazel": "8a43b7df601a7ec1af61d79345c17b31ea1fedc6711fd4abfd013ea612978e39",
diff --git a/copy_pkg.bzl b/copy_pkg.bzl
index c111e0a..01e9fa9 100644
--- a/copy_pkg.bzl
+++ b/copy_pkg.bzl
@@ -8,6 +8,7 @@
             webpack_bundle,
             "//src/icons",
             "//src/static",
+            "//manifest",
         ] + get_static_styles_labels(),
         out = out,
         exclude_srcs_patterns = [
@@ -16,6 +17,7 @@
             "**/*.bzl",
         ],
         replace_prefixes = {
+            "manifest": "",
             "src/icons/*": "icons",
             "src/static": "",
             "webpack_bundle": "",
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..a52d6b3
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,8 @@
+// We are only using Go to use tools inside Bazel, and we're not exporting nor
+// compiling any local code.
+
+module infinitegforums
+
+go 1.25.0
+
+require gomodules.avm99963.com/webext v0.0.0-20231229234506-1c9c8f9b5c3e
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..5a58a73
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+gomodules.avm99963.com/webext v0.0.0-20231229234506-1c9c8f9b5c3e h1:jmMYgCg+nA7qgSlWhG3C7fZFj83LjthYucDi0ybgyP0=
+gomodules.avm99963.com/webext v0.0.0-20231229234506-1c9c8f9b5c3e/go.mod h1:Vy9K/wxbDkqNngFJSH3ZPLjFyaaQyV8TcDUKN3a67Vo=
diff --git a/manifest/BUILD.bazel b/manifest/BUILD.bazel
new file mode 100644
index 0000000..184f412
--- /dev/null
+++ b/manifest/BUILD.bazel
@@ -0,0 +1,31 @@
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
+
+alias(
+    name = "genmanifest",
+    actual = "@com_avm99963_gomodules_webext//genmanifest",
+)
+
+# A template of the manifest adapted for the selected platform.
+run_binary(
+    name = "platform_manifest_template",
+    srcs = ["manifest.template.gjson"],
+    outs = ["manifest.template.json"],
+    args = [
+        "-template",
+        "$(location manifest.template.gjson)",
+        "-dest",
+        "$(location manifest.template.json)",
+    ] + select({
+        "//:chromium": ["CHROMIUM_MV3"],
+        "//:gecko": ["GECKO"],
+    }),
+    tool = "genmanifest",
+)
+
+# TODO(https://iavm.xyz/b/twpowertools/255): fill in the template with the
+# actual information.
+alias(
+    name = "manifest",
+    actual = "platform_manifest_template",
+    visibility = ["//:__pkg__"],
+)
diff --git a/templates/manifest.gjson b/manifest/manifest.template.gjson
similarity index 100%
rename from templates/manifest.gjson
rename to manifest/manifest.template.gjson
diff --git a/tools/tools.go b/tools/tools.go
new file mode 100644
index 0000000..303d485
--- /dev/null
+++ b/tools/tools.go
@@ -0,0 +1,11 @@
+//go:build tools
+// +build tools
+
+package tools
+
+// These imports only exist to keep go.mod entries for packages that are referenced
+// in BUILD files, but not in Go code.
+
+import (
+	_ "gomodules.avm99963.com/webext/genmanifest"
+)
diff --git a/webpack.config.js b/webpack.config.js
index eabb0d4..630c7ab 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -22,7 +22,7 @@
 
 module.exports = (env, args) => {
   // NOTE: When adding an entry, add the corresponding source map file to
-  // web_accessible_resources in //templates/manifest.gjson.
+  // web_accessible_resources in //manifest/manifest.template.gjson.
   const entry = {
     // Content scripts
     communityConsoleMain:
@@ -74,7 +74,7 @@
   };
 
   // NOTE: When adding an entry, add the corresponding source map file to
-  // web_accessible_resources in //templates/manifest.gjson.
+  // web_accessible_resources in //manifest/manifest.template.gjson.
   // Keep this synced with tools/static_styles_provider.bzl as well.
   const styles = [
     {
@@ -170,7 +170,7 @@
       !isBazelBuild ? new WebpackShellPluginNext({
         onBuildEnd: {
           scripts:
-              ['genmanifest -template templates/manifest.gjson -dest ' +
+              ['genmanifest -template manifest/manifest.template.gjson -dest ' +
                path.join(outputPath, 'manifest.json') + ' ' +
                env.browser_target]
         },