[bazel] Update support files.

This adds a MODULE.bazel file matching the sources
in the current repository, and updates BUILD.bazel to
provide definitions that match the ones from the module
of the same name in the Bazel Central Registry.

Note that this does *not* update the sources to the BCR
version, since they include many third-party convenience
libraries too, some of them using a Fuchsia-incompatible
license.

Note that the main target lists are now `zlib` and `z`
to match the BCR module. The target names `zlibonly`
et al are never used in the Bazel part of the
Fuchsia build anyway.

+ Remove invalid definitions, e.g. there is no
  contrib/optimizations/ directory at all so the glob()
  calls were returning empty lists.

After this CL is submitted, it will be possible to add
a new @zlib top-level module that points to
//third_party/zlib.

Change-Id: I47b525dac4a7c2afe44c031deccc6a54e3ef3795
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/zlib/+/1496496
Reviewed-by: Francois Rousseau <frousseau@google.com>
diff --git a/BUILD.bazel b/BUILD.bazel
index 1f995e3..0b6d8e9 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -2,82 +2,88 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@rules_license//rules:license.bzl", "license")
+
 """zlib is a general purpose data compression library."""
 
-ZLIB_COPTS = [
-    "-Wno-implicit-function-declaration",
-    "-Wno-conversion",
-    "-Wno-implicit-fallthrough",
-    "-Wno-strict-prototypes",
+package(
+    default_applicable_licenses = [":license"]
+)
+
+license(
+    name = "license",
+    license_kinds = ["@rules_license//licenses/spdx:Zlib"],
+    license_text = "LICENSE",
+)
+
+exports_files([
+    "LICENSE",
+])
+
+_ZLIB_HEADERS = [
+    "crc32.h",
+    "deflate.h",
+    "gzguts.h",
+    "inffast.h",
+    "inffixed.h",
+    "inflate.h",
+    "inftrees.h",
+    "trees.h",
+    "zconf.h",
+    "zlib.h",
+    "zutil.h",
 ]
 
-# This library exposes the headers both as the google3-preferred
-# "third_party/zlib/zlib.h" as well as externally-typical <zlib.h>.
+config_setting(
+    name = "mingw_gcc_compiler",
+    flag_values = {
+        "@bazel_tools//tools/cpp:compiler": "mingw-gcc",
+    },
+    visibility = [":__subpackages__"],
+)
+
 cc_library(
-    name = "zlibonly",
-    hdrs = [
-        "zconf.h",
-        "zlib.h",
+    name = "z",
+    srcs = [
+        "adler32.c",
+        "compress.c",
+        "crc32.c",
+        "deflate.c",
+        "gzclose.c",
+        "gzlib.c",
+        "gzread.c",
+        "gzwrite.c",
+        "infback.c",
+        "inffast.c",
+        "inflate.c",
+        "inftrees.c",
+        "trees.c",
+        "uncompr.c",
+        "zutil.c",
     ],
-    copts = ZLIB_COPTS,
-    include_prefix = "third_party/zlib",
-    includes = ["."],
+    hdrs = _ZLIB_HEADERS,
+    copts = select({
+        ":mingw_gcc_compiler": [
+            "-fpermissive",
+        ],
+        "@platforms//os:windows": [],
+        "@platforms//os:macos": [
+            "-Wno-unused-variable",
+            "-Wno-implicit-function-declaration",
+        ],
+        "//conditions:default": [
+            "-Wno-deprecated-non-prototype",
+            "-Wno-unused-variable",
+            "-Wno-implicit-function-declaration",
+            "-Wno-strict-prototypes",
+        ],
+    }),
     visibility = ["//visibility:public"],
-    deps = [":zlibonlyimpl"],
 )
 
 alias(
-    name = "zlibsystem",
-    actual = ":zlibonly",
+    name = "zlib",
+    actual = ":z",
     visibility = ["//visibility:public"],
 )
-
-# If you add or remove source files from this list, you should make the
-# same change in zlib.gyp.
-ZLIB_SOURCES = [
-    "adler32.c",
-    "compress.c",
-    "crc32.c",
-    "deflate.c",
-    "gzclose.c",
-    "gzlib.c",
-    "gzread.c",
-    "gzwrite.c",
-    "infback.c",
-    "inffast.c",
-    "inftrees.c",
-    "trees.c",
-    "uncompr.c",
-    "zutil.c",
-] + select({
-    "//build/bazel/platforms/arch:arm64": glob([
-        "contrib/optimizations/*.c",
-    ]),
-    "//conditions:default": ["inflate.c"],
-})
-
-ZLIB_HEADERS = glob(
-    [
-        "*.h",
-        "contrib/optimizations/*.h",
-    ],
-)
-
-ZLIB_DEFINES = ["ZLIB_IMPLEMENTATION"]
-
-cc_library(
-    name = "zlibonlyimpl",
-    srcs = ZLIB_SOURCES,
-    copts = [
-        "-Wno-implicit-function-declaration",
-    ] + ZLIB_COPTS,
-    includes = ["src"],
-    local_defines = ZLIB_DEFINES,
-    deps = [":zlibonly_internal_hdrs"],
-)
-
-cc_library(
-    name = "zlibonly_internal_hdrs",
-    textual_hdrs = ZLIB_HEADERS,
-    visibility = ["//visibility:private"],
-)
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 0000000..8617f55
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,11 @@
+# Copyright 2026 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+module(
+    name = "zlib",
+    version = "1.2.11",
+    compatibility_level = 1,
+)
+bazel_dep(name = "platforms", version = "0.0.7")
+bazel_dep(name = "rules_cc", version = "0.0.8")
+bazel_dep(name = "rules_license", version = "1.0.0")