Allow MLIR external repository to be created from non-tensorflow repository.

PiperOrigin-RevId: 268519854
diff --git a/tensorflow/opensource_only.files b/tensorflow/opensource_only.files
index 557fb2a..2df9c1d 100644
--- a/tensorflow/opensource_only.files
+++ b/tensorflow/opensource_only.files
@@ -1,4 +1,4 @@
-llvm/llvm/projects/google_mlir/WORKSPACE
+llvm/llvm/projects/google_mlir/mlir_configure.bzl
 tensorflow/__init__.py
 tensorflow/api_template.__init__.py
 tensorflow/api_template_v1.__init__.py
diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl
index 631b118..661d084 100755
--- a/tensorflow/workspace.bzl
+++ b/tensorflow/workspace.bzl
@@ -7,6 +7,7 @@
 load("//third_party/mkl:build_defs.bzl", "mkl_repository")
 load("//third_party/git:git_configure.bzl", "git_configure")
 load("//third_party/py:python_configure.bzl", "python_configure")
+load("//third_party/mlir:mlir_configure.bzl", "mlir_configure")
 load("//third_party/sycl:sycl_configure.bzl", "sycl_configure")
 load("//third_party/systemlibs:syslibs_configure.bzl", "syslibs_configure")
 load("//third_party/toolchains/remote:configure.bzl", "remote_execution_configure")
@@ -75,10 +76,7 @@
     syslibs_configure(name = "local_config_syslibs")
     python_configure(name = "local_config_python")
     rocm_configure(name = "local_config_rocm")
-    native.local_repository(
-        name = "local_config_mlir",
-        path = "third_party/mlir",
-    )
+    mlir_configure(name = "local_config_mlir")
     remote_execution_configure(name = "local_config_remote_execution")
 
     initialize_third_party()
diff --git a/third_party/mlir/WORKSPACE b/third_party/mlir/WORKSPACE
deleted file mode 100644
index e69de29..0000000
--- a/third_party/mlir/WORKSPACE
+++ /dev/null
diff --git a/third_party/mlir/mlir_configure.bzl b/third_party/mlir/mlir_configure.bzl
new file mode 100644
index 0000000..6ffbd90
--- /dev/null
+++ b/third_party/mlir/mlir_configure.bzl
@@ -0,0 +1,22 @@
+"""Repository rule for MLIR autoconfiguration."""
+
+def _mlir_configure_impl(repository_ctx):
+    repository_ctx.file("WORKSPACE", "")
+    label = Label("@org_tensorflow//third_party/mlir:mlir_configure.bzl")
+    for entry in repository_ctx.path(label).dirname.readdir():
+        repository_ctx.symlink(entry, entry.basename)
+
+mlir_configure = repository_rule(
+    implementation = _mlir_configure_impl,
+)
+"""Detects and configures the MLIR configuration.
+
+Add the following to your WORKSPACE FILE:
+
+```python
+mlir_configure(name = "local_config_mlir")
+```
+
+Args:
+  name: A unique name for this workspace rule.
+"""