Depend on granular TensorFlow targets.

The open source build of Riegeli/TensorFlow is still broken because TensorFlow
does not support bzlmod yet.

PiperOrigin-RevId: 885816369
diff --git a/riegeli/tensorflow/io/BUILD b/riegeli/tensorflow/io/BUILD
index 04b179a..494d892 100644
--- a/riegeli/tensorflow/io/BUILD
+++ b/riegeli/tensorflow/io/BUILD
@@ -12,6 +12,12 @@
     srcs = ["file_reader.cc"],
     hdrs = ["file_reader.h"],
     deps = [
+        "@com_google_absl//absl/base:core_headers",
+        "@com_google_absl//absl/status",
+        "@com_google_absl//absl/strings",
+        "@com_google_absl//absl/strings:cord",
+        "@com_google_absl//absl/strings:string_view",
+        "@com_google_absl//absl/types:span",
         "//riegeli/base:arithmetic",
         "//riegeli/base:assert",
         "//riegeli/base:buffering",
@@ -30,13 +36,8 @@
         "//riegeli/bytes:path_ref",
         "//riegeli/bytes:reader",
         "//riegeli/bytes:writer",
-        "@com_google_absl//absl/base:core_headers",
-        "@com_google_absl//absl/status",
-        "@com_google_absl//absl/strings",
-        "@com_google_absl//absl/strings:cord",
-        "@com_google_absl//absl/strings:string_view",
-        "@com_google_absl//absl/types:span",
-        "@local_config_tf//:tf_header_lib",
+        # TODO: Riegeli/TensorFlow build is currently broken
+        # in open source because TensorFlow does not support bzlmod yet.
     ],
 )
 
@@ -46,13 +47,18 @@
     hdrs = ["file_writer.h"],
     deps = [
         ":file_reader",
+        "@com_google_absl//absl/base:core_headers",
+        "@com_google_absl//absl/status",
+        "@com_google_absl//absl/strings",
+        "@com_google_absl//absl/strings:string_view",
+        "@com_google_absl//absl/strings:cord",
         "//riegeli/base:arithmetic",
         "//riegeli/base:assert",
         "//riegeli/base:buffering",
-        "//riegeli/base:byte_fill",
         "//riegeli/base:chain",
         "//riegeli/base:dependency",
         "//riegeli/base:external_ref",
+        "//riegeli/base:byte_fill",
         "//riegeli/base:initializer",
         "//riegeli/base:object",
         "//riegeli/base:reset",
@@ -63,12 +69,8 @@
         "//riegeli/bytes:path_ref",
         "//riegeli/bytes:reader",
         "//riegeli/bytes:writer",
-        "@com_google_absl//absl/base:core_headers",
-        "@com_google_absl//absl/status",
-        "@com_google_absl//absl/strings",
-        "@com_google_absl//absl/strings:cord",
-        "@com_google_absl//absl/strings:string_view",
-        "@local_config_tf//:tf_header_lib",
+        # TODO: Riegeli/TensorFlow build is currently broken
+        # in open source because TensorFlow does not support bzlmod yet.
     ],
 )
 
@@ -82,6 +84,7 @@
         "//riegeli/base:initializer",
         "//riegeli/base:object",
         "//riegeli/bytes:resizable_writer",
-        "@local_config_tf//:tf_header_lib",
+        # TODO: Riegeli/TensorFlow build is currently broken
+        # in open source because TensorFlow does not support bzlmod yet.
     ],
 )
diff --git a/riegeli/tensorflow/io/file_reader.cc b/riegeli/tensorflow/io/file_reader.cc
index 3ff5049..fddb5cb 100644
--- a/riegeli/tensorflow/io/file_reader.cc
+++ b/riegeli/tensorflow/io/file_reader.cc
@@ -46,13 +46,13 @@
 #include "riegeli/bytes/path_ref.h"
 #include "riegeli/bytes/reader.h"
 #include "riegeli/bytes/writer.h"
-#include "tensorflow/core/platform/env.h"
-#include "tensorflow/core/platform/file_system.h"
+#include "tensorflow/compiler/xla/tsl/platform/env.h"
+#include "tensorflow/compiler/xla/tsl/platform/file_system.h"
 #include "tensorflow/core/public/version.h"
 
 namespace riegeli::tensorflow {
 
-bool FileReaderBase::InitializeFilename(::tensorflow::RandomAccessFile* src) {
+bool FileReaderBase::InitializeFilename(tsl::RandomAccessFile* src) {
   absl::string_view filename;
   if (const absl::Status status = src->Name(&filename);
       ABSL_PREDICT_FALSE(!status.ok())) {
@@ -75,8 +75,8 @@
   return true;
 }
 
-std::unique_ptr<::tensorflow::RandomAccessFile> FileReaderBase::OpenFile() {
-  std::unique_ptr<::tensorflow::RandomAccessFile> src;
+std::unique_ptr<tsl::RandomAccessFile> FileReaderBase::OpenFile() {
+  std::unique_ptr<tsl::RandomAccessFile> src;
   if (const absl::Status status =
           file_system_->NewRandomAccessFile(filename_, &src);
       ABSL_PREDICT_FALSE(!status.ok())) {
@@ -142,7 +142,7 @@
       << "Failed precondition of Reader::PullSlow(): "
          "enough data available, use Pull() instead";
   if (ABSL_PREDICT_FALSE(!ok())) return false;
-  ::tensorflow::RandomAccessFile* const src = SrcFile();
+  tsl::RandomAccessFile* const src = SrcFile();
   const size_t available_length = available();
   const size_t buffer_length = buffer_sizer_.BufferLength(
       limit_pos(), min_length - available_length,
@@ -175,8 +175,7 @@
 }
 
 inline bool FileReaderBase::ReadToDest(size_t length,
-                                       ::tensorflow::RandomAccessFile* src,
-                                       char* dest) {
+                                       tsl::RandomAccessFile* src, char* dest) {
   if (ABSL_PREDICT_FALSE(limit_pos() >= std::numeric_limits<uint64_t>::max())) {
     return FailOverflow();
   }
@@ -209,7 +208,7 @@
 }
 
 inline bool FileReaderBase::ReadToBuffer(size_t cursor_index,
-                                         ::tensorflow::RandomAccessFile* src,
+                                         tsl::RandomAccessFile* src,
                                          absl::Span<char> flat_buffer) {
   RIEGELI_ASSERT(flat_buffer.data() + flat_buffer.size() ==
                  buffer_.data() + buffer_.size())
@@ -272,7 +271,7 @@
     dest += available_length;
     length -= available_length;
     if (ABSL_PREDICT_FALSE(!ok())) return false;
-    ::tensorflow::RandomAccessFile* const src = SrcFile();
+    tsl::RandomAccessFile* const src = SrcFile();
     SyncBuffer();
     size_t length_to_read = length;
     if (exact_size() != std::nullopt) {
@@ -294,7 +293,7 @@
   RIEGELI_ASSERT_LE(length, std::numeric_limits<size_t>::max() - dest.size())
       << "Failed precondition of Reader::ReadSlow(Chain&): "
          "Chain size overflow";
-  ::tensorflow::RandomAccessFile* const src = SrcFile();
+  tsl::RandomAccessFile* const src = SrcFile();
   bool enough_read = true;
   while (length > available()) {
     const size_t available_length = available();
@@ -361,7 +360,7 @@
   RIEGELI_ASSERT_LE(length, std::numeric_limits<size_t>::max() - dest.size())
       << "Failed precondition of Reader::ReadSlow(Cord&): "
          "Cord size overflow";
-  ::tensorflow::RandomAccessFile* const src = SrcFile();
+  tsl::RandomAccessFile* const src = SrcFile();
   bool enough_read = true;
   while (length > available()) {
     const size_t available_length = available();
@@ -426,7 +425,7 @@
   RIEGELI_ASSERT_LT(UnsignedMin(available(), kMaxBytesToCopy), length)
       << "Failed precondition of Reader::CopySlow(Writer&): "
          "enough data available, use Copy(Writer&) instead";
-  ::tensorflow::RandomAccessFile* const src = SrcFile();
+  tsl::RandomAccessFile* const src = SrcFile();
   bool enough_read = true;
   while (length > available()) {
     const size_t available_length = available();
@@ -519,7 +518,7 @@
 }
 
 inline bool FileReaderBase::CopyUsingPush(Position length,
-                                          ::tensorflow::RandomAccessFile* src,
+                                          tsl::RandomAccessFile* src,
                                           Writer& dest) {
   RIEGELI_ASSERT_GT(length, 0u)
       << "Failed precondition of FileReaderBase::CopyUsingPush(): "
@@ -577,7 +576,7 @@
   if (max_length >= buffer_sizer_.BufferLength(limit_pos())) {
     // Read directly to `dest`.
     if (ABSL_PREDICT_FALSE(!ok())) return false;
-    ::tensorflow::RandomAccessFile* const src = SrcFile();
+    tsl::RandomAccessFile* const src = SrcFile();
     SyncBuffer();
     if (exact_size() != std::nullopt) {
       if (ABSL_PREDICT_FALSE(limit_pos() >= *exact_size())) return false;
@@ -602,7 +601,7 @@
   if (max_length >= buffer_sizer_.BufferLength(limit_pos())) {
     // Copy directly to `dest`.
     if (ABSL_PREDICT_FALSE(!ok())) return false;
-    ::tensorflow::RandomAccessFile* const src = SrcFile();
+    tsl::RandomAccessFile* const src = SrcFile();
     SyncBuffer();
     if (exact_size() != std::nullopt) {
       if (ABSL_PREDICT_FALSE(limit_pos() >= *exact_size())) return false;
@@ -697,9 +696,9 @@
   }
   if (ABSL_PREDICT_FALSE(!ok())) return nullptr;
   // `NewReaderImpl()` is thread-safe from this point.
-  ::tensorflow::RandomAccessFile* const src = SrcFile();
-  std::unique_ptr<FileReader<::tensorflow::RandomAccessFile*>> reader =
-      std::make_unique<FileReader<::tensorflow::RandomAccessFile*>>(
+  tsl::RandomAccessFile* const src = SrcFile();
+  std::unique_ptr<FileReader<tsl::RandomAccessFile*>> reader =
+      std::make_unique<FileReader<tsl::RandomAccessFile*>>(
           src, FileReaderBase::Options()
                    .set_env(env_)
                    .set_initial_pos(initial_pos)
diff --git a/riegeli/tensorflow/io/file_reader.h b/riegeli/tensorflow/io/file_reader.h
index d63a801..f2a13a9 100644
--- a/riegeli/tensorflow/io/file_reader.h
+++ b/riegeli/tensorflow/io/file_reader.h
@@ -40,8 +40,8 @@
 #include "riegeli/bytes/buffer_options.h"
 #include "riegeli/bytes/path_ref.h"
 #include "riegeli/bytes/reader.h"
-#include "tensorflow/core/platform/env.h"
-#include "tensorflow/core/platform/file_system.h"
+#include "tensorflow/compiler/xla/tsl/platform/env.h"
+#include "tensorflow/compiler/xla/tsl/platform/file_system.h"
 
 namespace riegeli {
 
@@ -63,17 +63,17 @@
 
     // Overrides the TensorFlow environment.
     //
-    // `nullptr` is interpreted as `::tensorflow::Env::Default()`.
+    // `nullptr` is interpreted as `tsl::Env::Default()`.
     //
     // Default: `nullptr`.
-    Options& set_env(::tensorflow::Env* env) & ABSL_ATTRIBUTE_LIFETIME_BOUND {
+    Options& set_env(tsl::Env* env) & ABSL_ATTRIBUTE_LIFETIME_BOUND {
       env_ = env;
       return *this;
     }
-    Options&& set_env(::tensorflow::Env* env) && ABSL_ATTRIBUTE_LIFETIME_BOUND {
+    Options&& set_env(tsl::Env* env) && ABSL_ATTRIBUTE_LIFETIME_BOUND {
       return std::move(set_env(env));
     }
-    ::tensorflow::Env* env() const { return env_; }
+    tsl::Env* env() const { return env_; }
 
     // Reading will start from this position.
     //
@@ -105,18 +105,18 @@
     bool growing_source() const { return growing_source_; }
 
    private:
-    ::tensorflow::Env* env_ = nullptr;
+    tsl::Env* env_ = nullptr;
     Position initial_pos_ = 0;
     bool growing_source_ = false;
   };
 
-  // Returns the `::tensorflow::RandomAccessFile` being read from. If the
-  // `::tensorflow::RandomAccessFile` is owned then changed to `nullptr` by
+  // Returns the `tsl::RandomAccessFile` being read from. If the
+  // `tsl::RandomAccessFile` is owned then changed to `nullptr` by
   // `Close()`, otherwise unchanged.
-  virtual ::tensorflow::RandomAccessFile* SrcFile() const
+  virtual tsl::RandomAccessFile* SrcFile() const
       ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
 
-  // Returns the name of the `::tensorflow::RandomAccessFile` being read from.
+  // Returns the name of the `tsl::RandomAccessFile` being read from.
   // Unchanged by `Close()`.
   absl::string_view filename() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
     return filename_;
@@ -134,19 +134,18 @@
  protected:
   explicit FileReaderBase(Closed) noexcept : Reader(kClosed) {}
 
-  explicit FileReaderBase(BufferOptions buffer_options, ::tensorflow::Env* env,
+  explicit FileReaderBase(BufferOptions buffer_options, tsl::Env* env,
                           bool growing_source);
 
   FileReaderBase(FileReaderBase&& that) noexcept;
   FileReaderBase& operator=(FileReaderBase&& that) noexcept;
 
   void Reset(Closed);
-  void Reset(BufferOptions buffer_options, ::tensorflow::Env* env,
-             bool growing_source);
-  void Initialize(::tensorflow::RandomAccessFile* src, Position initial_pos);
-  bool InitializeFilename(::tensorflow::RandomAccessFile* src);
+  void Reset(BufferOptions buffer_options, tsl::Env* env, bool growing_source);
+  void Initialize(tsl::RandomAccessFile* src, Position initial_pos);
+  bool InitializeFilename(tsl::RandomAccessFile* src);
   bool InitializeFilename(PathInitializer filename);
-  std::unique_ptr<::tensorflow::RandomAccessFile> OpenFile();
+  std::unique_ptr<tsl::RandomAccessFile> OpenFile();
   void InitializePos(Position initial_pos);
 
   void Done() override;
@@ -189,8 +188,7 @@
   // position which is `limit_pos()`, to `dest[]`.
   //
   // Increments `limit_pos()` by the length read. Returns `true` on success.
-  bool ReadToDest(size_t length, ::tensorflow::RandomAccessFile* src,
-                  char* dest);
+  bool ReadToDest(size_t length, tsl::RandomAccessFile* src, char* dest);
 
   // Reads `flat_buffer.size()` bytes from `*src`, from the physical file
   // position which is `limit_pos()`, preferably to `flat_buffer.data()`. Newly
@@ -202,25 +200,24 @@
   // `true` on success.
   //
   // Precondition: `flat_buffer` is a suffix of `buffer_`
-  bool ReadToBuffer(size_t cursor_index, ::tensorflow::RandomAccessFile* src,
+  bool ReadToBuffer(size_t cursor_index, tsl::RandomAccessFile* src,
                     absl::Span<char> flat_buffer);
 
   // Implementation of `CopySlow(Writer&)` in terms of `Writer::Push()` and
   // `ReadToDest()`. Does not use buffer pointers.
   //
   // Precondition: `length > 0`
-  bool CopyUsingPush(Position length, ::tensorflow::RandomAccessFile* src,
-                     Writer& dest);
+  bool CopyUsingPush(Position length, tsl::RandomAccessFile* src, Writer& dest);
 
   std::string filename_{kDefaultFilename};
   // Invariant: if `is_open()` then `env_ != nullptr`
-  ::tensorflow::Env* env_ = nullptr;
-  ::tensorflow::FileSystem* file_system_ = nullptr;
+  tsl::Env* env_ = nullptr;
+  tsl::FileSystem* file_system_ = nullptr;
   bool growing_source_ = false;
   ReadBufferSizer buffer_sizer_;
   // If `buffer_` is not empty, it contains buffered data, read directly before
   // the physical source position which is `limit_pos()`. Otherwise buffered
-  // data are in memory managed by the `::tensorflow::RandomAccessFile`. In any
+  // data are in memory managed by the `tsl::RandomAccessFile`. In any
   // case `start()` points to them.
   SizedSharedBuffer buffer_;
 
@@ -229,34 +226,34 @@
   //   `start_to_limit() == buffer_.size()`
 };
 
-// A `Reader` which reads from a `::tensorflow::RandomAccessFile`.
+// A `Reader` which reads from a `tsl::RandomAccessFile`.
 //
 // It supports random access and `NewReader()` if the
-// `::tensorflow::RandomAccessFile` supports
-// `::tensorflow::RandomAccessFile::Name()` and the name is not empty.
+// `tsl::RandomAccessFile` supports
+// `tsl::RandomAccessFile::Name()` and the name is not empty.
 //
 // The `Src` template parameter specifies the type of the object providing and
-// possibly owning the `::tensorflow::RandomAccessFile` being read from. `Src`
-// must support `Dependency<::tensorflow::RandomAccessFile*, Src>`, e.g.
-// `std::unique_ptr<::tensorflow::RandomAccessFile>` (owned, default),
-// `::tensorflow::RandomAccessFile*` (not owned),
-// `Any<::tensorflow::RandomAccessFile*>` (maybe owned).
+// possibly owning the `tsl::RandomAccessFile` being read from. `Src`
+// must support `Dependency<tsl::RandomAccessFile*, Src>`, e.g.
+// `std::unique_ptr<tsl::RandomAccessFile>` (owned, default),
+// `tsl::RandomAccessFile*` (not owned),
+// `Any<tsl::RandomAccessFile*>` (maybe owned).
 //
 // By relying on CTAD the template argument can be deduced as `TargetT` of the
 // type of the first constructor argument.
 //
-// The `::tensorflow::RandomAccessFile` must not be closed until the
+// The `tsl::RandomAccessFile` must not be closed until the
 // `FileReader` is closed or no longer used.
-template <typename Src = std::unique_ptr<::tensorflow::RandomAccessFile>>
+template <typename Src = std::unique_ptr<tsl::RandomAccessFile>>
 class FileReader : public FileReaderBase {
  public:
   // Creates a closed `FileReader`.
   explicit FileReader(Closed) noexcept : FileReaderBase(kClosed) {}
 
-  // Will read from the `::tensorflow::RandomAccessFile` provided by `src`.
+  // Will read from the `tsl::RandomAccessFile` provided by `src`.
   explicit FileReader(Initializer<Src> src, Options options = Options());
 
-  // Opens a `::tensorflow::RandomAccessFile` for reading.
+  // Opens a `tsl::RandomAccessFile` for reading.
   //
   // If opening the file fails, `FileReader` will be failed and closed.
   explicit FileReader(PathInitializer filename, Options options = Options());
@@ -273,14 +270,14 @@
   void Reset(PathInitializer filename, Options options = Options());
 
   // Returns the object providing and possibly owning the
-  // `::tensorflow::RandomAccessFile` being read from. If the
-  // `::tensorflow::RandomAccessFile` is owned then changed to `nullptr` by
+  // `tsl::RandomAccessFile` being read from. If the
+  // `tsl::RandomAccessFile` is owned then changed to `nullptr` by
   // `Close()`, otherwise unchanged.
   Src& src() ABSL_ATTRIBUTE_LIFETIME_BOUND { return src_.manager(); }
   const Src& src() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
     return src_.manager();
   }
-  ::tensorflow::RandomAccessFile* SrcFile() const
+  tsl::RandomAccessFile* SrcFile() const
       ABSL_ATTRIBUTE_LIFETIME_BOUND override {
     return src_.get();
   }
@@ -293,8 +290,8 @@
   void Initialize(PathInitializer filename, Options&& options);
 
   // The object providing and possibly owning the
-  // `::tensorflow::RandomAccessFile` being read from.
-  Dependency<::tensorflow::RandomAccessFile*, Src> src_;
+  // `tsl::RandomAccessFile` being read from.
+  Dependency<tsl::RandomAccessFile*, Src> src_;
 };
 
 explicit FileReader(Closed) -> FileReader<DeleteCtad<Closed>>;
@@ -303,14 +300,13 @@
                     FileReaderBase::Options options = FileReaderBase::Options())
     -> FileReader<std::conditional_t<
         std::is_convertible_v<Src&&, PathInitializer>,
-        std::unique_ptr<::tensorflow::RandomAccessFile>, TargetT<Src>>>;
+        std::unique_ptr<tsl::RandomAccessFile>, TargetT<Src>>>;
 
 // Implementation details follow.
 
 inline FileReaderBase::FileReaderBase(BufferOptions buffer_options,
-                                      ::tensorflow::Env* env,
-                                      bool growing_source)
-    : env_(env != nullptr ? env : ::tensorflow::Env::Default()),
+                                      tsl::Env* env, bool growing_source)
+    : env_(env != nullptr ? env : tsl::Env::Default()),
       growing_source_(growing_source),
       buffer_sizer_(buffer_options) {}
 
@@ -345,18 +341,18 @@
   buffer_ = SizedSharedBuffer();
 }
 
-inline void FileReaderBase::Reset(BufferOptions buffer_options,
-                                  ::tensorflow::Env* env, bool growing_source) {
+inline void FileReaderBase::Reset(BufferOptions buffer_options, tsl::Env* env,
+                                  bool growing_source) {
   Reader::Reset();
   // `filename_` will be set by `InitializeFilename()`.
-  env_ = env != nullptr ? env : ::tensorflow::Env::Default();
+  env_ = env != nullptr ? env : tsl::Env::Default();
   file_system_ = nullptr;
   growing_source_ = growing_source;
   buffer_sizer_.Reset(buffer_options);
   buffer_.Clear();
 }
 
-inline void FileReaderBase::Initialize(::tensorflow::RandomAccessFile* src,
+inline void FileReaderBase::Initialize(tsl::RandomAccessFile* src,
                                        Position initial_pos) {
   RIEGELI_ASSERT_NE(src, nullptr)
       << "Failed precondition of FileReader: null RandomAccessFile pointer";
@@ -404,7 +400,7 @@
 inline void FileReader<Src>::Initialize(PathInitializer filename,
                                         Options&& options) {
   if (ABSL_PREDICT_FALSE(!InitializeFilename(std::move(filename)))) return;
-  std::unique_ptr<::tensorflow::RandomAccessFile> src = OpenFile();
+  std::unique_ptr<tsl::RandomAccessFile> src = OpenFile();
   if (ABSL_PREDICT_FALSE(src == nullptr)) return;
   src_.Reset(riegeli::Maker(src.release()));
   InitializePos(options.initial_pos());
@@ -414,7 +410,7 @@
 void FileReader<Src>::Done() {
   FileReaderBase::Done();
   if (src_.IsOwning()) {
-    // The only way to close a `::tensorflow::RandomAccessFile` is to delete it.
+    // The only way to close a `tsl::RandomAccessFile` is to delete it.
     src_.Reset();
   }
 }
diff --git a/riegeli/tensorflow/io/file_writer.cc b/riegeli/tensorflow/io/file_writer.cc
index da4c0ea..1980fa4 100644
--- a/riegeli/tensorflow/io/file_writer.cc
+++ b/riegeli/tensorflow/io/file_writer.cc
@@ -44,13 +44,13 @@
 #include "riegeli/bytes/reader.h"
 #include "riegeli/bytes/writer.h"
 #include "riegeli/tensorflow/io/file_reader.h"
-#include "tensorflow/core/platform/env.h"
-#include "tensorflow/core/platform/file_system.h"
+#include "tensorflow/compiler/xla/tsl/platform/env.h"
+#include "tensorflow/compiler/xla/tsl/platform/file_system.h"
 #include "tensorflow/core/public/version.h"
 
 namespace riegeli::tensorflow {
 
-bool FileWriterBase::InitializeFilename(::tensorflow::WritableFile* dest) {
+bool FileWriterBase::InitializeFilename(tsl::WritableFile* dest) {
   absl::string_view filename;
   if (const absl::Status status = dest->Name(&filename);
       ABSL_PREDICT_FALSE(!status.ok())) {
@@ -73,9 +73,8 @@
   return true;
 }
 
-std::unique_ptr<::tensorflow::WritableFile> FileWriterBase::OpenFile(
-    bool append) {
-  std::unique_ptr<::tensorflow::WritableFile> dest;
+std::unique_ptr<tsl::WritableFile> FileWriterBase::OpenFile(bool append) {
+  std::unique_ptr<tsl::WritableFile> dest;
   if (const absl::Status status =
           append ? file_system_->NewAppendableFile(filename_, &dest)
                  : file_system_->NewWritableFile(filename_, &dest);
@@ -92,7 +91,7 @@
   return dest;
 }
 
-void FileWriterBase::InitializePos(::tensorflow::WritableFile* dest) {
+void FileWriterBase::InitializePos(tsl::WritableFile* dest) {
   int64_t file_pos;
   if (const absl::Status status = dest->Tell(&file_pos);
       ABSL_PREDICT_FALSE(!status.ok())) {
@@ -174,7 +173,7 @@
          "nothing to write";
   RIEGELI_ASSERT_OK(*this)
       << "Failed precondition of FileWriterBase::WriteInternal()";
-  ::tensorflow::WritableFile* const dest = DestFile();
+  tsl::WritableFile* const dest = DestFile();
   if (ABSL_PREDICT_FALSE(src.size() >
                          std::numeric_limits<Position>::max() - start_pos())) {
     return FailOverflow();
@@ -281,7 +280,7 @@
          "nothing to write";
   RIEGELI_ASSERT_OK(*this)
       << "Failed precondition of FileWriterBase::WriteInternal()";
-  ::tensorflow::WritableFile* const dest = DestFile();
+  tsl::WritableFile* const dest = DestFile();
   if (ABSL_PREDICT_FALSE(src.size() >
                          std::numeric_limits<Position>::max() - start_pos())) {
     return FailOverflow();
diff --git a/riegeli/tensorflow/io/file_writer.h b/riegeli/tensorflow/io/file_writer.h
index 52152b9..2a571d0 100644
--- a/riegeli/tensorflow/io/file_writer.h
+++ b/riegeli/tensorflow/io/file_writer.h
@@ -41,8 +41,8 @@
 #include "riegeli/bytes/buffer_options.h"
 #include "riegeli/bytes/path_ref.h"
 #include "riegeli/bytes/writer.h"
-#include "tensorflow/core/platform/env.h"
-#include "tensorflow/core/platform/file_system.h"
+#include "tensorflow/compiler/xla/tsl/platform/env.h"
+#include "tensorflow/compiler/xla/tsl/platform/file_system.h"
 
 namespace riegeli {
 
@@ -66,17 +66,17 @@
 
     // Overrides the TensorFlow environment.
     //
-    // `nullptr` is interpreted as `::tensorflow::Env::Default()`.
+    // `nullptr` is interpreted as `tsl::Env::Default()`.
     //
     // Default: `nullptr`.
-    Options& set_env(::tensorflow::Env* env) & ABSL_ATTRIBUTE_LIFETIME_BOUND {
+    Options& set_env(tsl::Env* env) & ABSL_ATTRIBUTE_LIFETIME_BOUND {
       env_ = env;
       return *this;
     }
-    Options&& set_env(::tensorflow::Env* env) && ABSL_ATTRIBUTE_LIFETIME_BOUND {
+    Options&& set_env(tsl::Env* env) && ABSL_ATTRIBUTE_LIFETIME_BOUND {
       return std::move(set_env(env));
     }
-    ::tensorflow::Env* env() const { return env_; }
+    tsl::Env* env() const { return env_; }
 
     // If `false`, the file will be truncated to empty if it exists.
     //
@@ -97,16 +97,15 @@
     bool append() const { return append_; }
 
    private:
-    ::tensorflow::Env* env_ = nullptr;
+    tsl::Env* env_ = nullptr;
     bool append_ = false;
   };
 
-  // Returns the `::tensorflow::WritableFile` being written to. Unchanged by
+  // Returns the `tsl::WritableFile` being written to. Unchanged by
   // `Close()`.
-  virtual ::tensorflow::WritableFile* DestFile() const
-      ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
+  virtual tsl::WritableFile* DestFile() const ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
 
-  // Returns the name of the `::tensorflow::WritableFile` being written to.
+  // Returns the name of the `tsl::WritableFile` being written to.
   // Unchanged by `Close()`.
   absl::string_view filename() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
     return filename_;
@@ -117,18 +116,18 @@
  protected:
   explicit FileWriterBase(Closed) noexcept : Writer(kClosed) {}
 
-  explicit FileWriterBase(BufferOptions buffer_options, ::tensorflow::Env* env);
+  explicit FileWriterBase(BufferOptions buffer_options, tsl::Env* env);
 
   FileWriterBase(FileWriterBase&& that) noexcept;
   FileWriterBase& operator=(FileWriterBase&& that) noexcept;
 
   void Reset(Closed);
-  void Reset(BufferOptions buffer_options, ::tensorflow::Env* env);
-  void Initialize(::tensorflow::WritableFile* dest);
-  bool InitializeFilename(::tensorflow::WritableFile* dest);
+  void Reset(BufferOptions buffer_options, tsl::Env* env);
+  void Initialize(tsl::WritableFile* dest);
+  bool InitializeFilename(tsl::WritableFile* dest);
   bool InitializeFilename(PathInitializer filename);
-  std::unique_ptr<::tensorflow::WritableFile> OpenFile(bool append);
-  void InitializePos(::tensorflow::WritableFile* dest);
+  std::unique_ptr<tsl::WritableFile> OpenFile(bool append);
+  void InitializePos(tsl::WritableFile* dest);
   ABSL_ATTRIBUTE_COLD bool FailOperation(const absl::Status& status,
                                          absl::string_view operation);
 
@@ -163,46 +162,46 @@
 
   std::string filename_{kDefaultFilename};
   // Invariant: if `is_open()` then `env_ != nullptr`
-  ::tensorflow::Env* env_ = nullptr;
-  ::tensorflow::FileSystem* file_system_ = nullptr;
+  tsl::Env* env_ = nullptr;
+  tsl::FileSystem* file_system_ = nullptr;
   WriteBufferSizer buffer_sizer_;
   // Buffered data to be written.
   SharedBuffer buffer_;
 
-  AssociatedReader<FileReader<std::unique_ptr<::tensorflow::RandomAccessFile>>>
+  AssociatedReader<FileReader<std::unique_ptr<tsl::RandomAccessFile>>>
       associated_reader_;
 };
 
-// A `Writer` which writes to a `::tensorflow::WritableFile`.
+// A `Writer` which writes to a `tsl::WritableFile`.
 //
-// It supports `ReadMode()` if the `::tensorflow::WritableFile` supports
-// `::tensorflow::WritableFile::Name()` and the name is not empty.
+// It supports `ReadMode()` if the `tsl::WritableFile` supports
+// `tsl::WritableFile::Name()` and the name is not empty.
 //
 // The `Dest` template parameter specifies the type of the object providing and
-// possibly owning the `::tensorflow::WritableFile` being written to. `Dest`
-// must support `Dependency<::tensorflow::WritableFile*, Dest>`, e.g.
-// `std::unique_ptr<::tensorflow::WritableFile>` (owned, default),
-// `::tensorflow::WritableFile*` (not owned),
-// `Any<::tensorflow::WritableFile*>` (maybe owned).
+// possibly owning the `tsl::WritableFile` being written to. `Dest`
+// must support `Dependency<tsl::WritableFile*, Dest>`, e.g.
+// `std::unique_ptr<tsl::WritableFile>` (owned, default),
+// `tsl::WritableFile*` (not owned),
+// `Any<tsl::WritableFile*>` (maybe owned).
 //
 // By relying on CTAD the template argument can be deduced as `TargetT` of the
 // type of the first constructor argument.
 //
-// The `::tensorflow::WritableFile` must not be closed until the `FileWriter` is
-// closed or no longer used. Until then the `::tensorflow::WritableFile` may be
+// The `tsl::WritableFile` must not be closed until the `FileWriter` is
+// closed or no longer used. Until then the `tsl::WritableFile` may be
 // accessed, but not concurrently, `Flush()` is needed before switching to
-// another writer to the same `::tensorflow::WritableFile`, and `pos()` does not
+// another writer to the same `tsl::WritableFile`, and `pos()` does not
 // take other writers into account.
-template <typename Dest = std::unique_ptr<::tensorflow::WritableFile>>
+template <typename Dest = std::unique_ptr<tsl::WritableFile>>
 class FileWriter : public FileWriterBase {
  public:
   // Creates a closed `FileWriter`.
   explicit FileWriter(Closed) noexcept : FileWriterBase(kClosed) {}
 
-  // Will write to the `::tensorflow::WritableFile` provided by `dest`.
+  // Will write to the `tsl::WritableFile` provided by `dest`.
   explicit FileWriter(Initializer<Dest> dest, Options options = Options());
 
-  // Opens a `::tensorflow::WritableFile` for writing.
+  // Opens a `tsl::WritableFile` for writing.
   //
   // If opening the file fails, `FileWriter` will be failed and closed.
   explicit FileWriter(PathInitializer filename, Options options = Options());
@@ -219,13 +218,12 @@
   void Reset(PathInitializer filename, Options options = Options());
 
   // Returns the object providing and possibly owning the
-  // `::tensorflow::WritableFile` being written to. Unchanged by `Close()`.
+  // `tsl::WritableFile` being written to. Unchanged by `Close()`.
   Dest& dest() ABSL_ATTRIBUTE_LIFETIME_BOUND { return dest_.manager(); }
   const Dest& dest() const ABSL_ATTRIBUTE_LIFETIME_BOUND {
     return dest_.manager();
   }
-  ::tensorflow::WritableFile* DestFile() const
-      ABSL_ATTRIBUTE_LIFETIME_BOUND override {
+  tsl::WritableFile* DestFile() const ABSL_ATTRIBUTE_LIFETIME_BOUND override {
     return dest_.get();
   }
 
@@ -237,24 +235,24 @@
   using FileWriterBase::Initialize;
   void Initialize(PathInitializer filename, Options&& options);
 
-  // The object providing and possibly owning the `::tensorflow::WritableFile`
+  // The object providing and possibly owning the `tsl::WritableFile`
   // being written to.
-  Dependency<::tensorflow::WritableFile*, Dest> dest_;
+  Dependency<tsl::WritableFile*, Dest> dest_;
 };
 
 explicit FileWriter(Closed) -> FileWriter<DeleteCtad<Closed>>;
 template <typename Dest>
 explicit FileWriter(Dest&& dest,
                     FileWriterBase::Options options = FileWriterBase::Options())
-    -> FileWriter<std::conditional_t<
-        std::is_convertible_v<Dest&&, PathInitializer>,
-        std::unique_ptr<::tensorflow::WritableFile>, TargetT<Dest>>>;
+    -> FileWriter<
+        std::conditional_t<std::is_convertible_v<Dest&&, PathInitializer>,
+                           std::unique_ptr<tsl::WritableFile>, TargetT<Dest>>>;
 
 // Implementation details follow.
 
 inline FileWriterBase::FileWriterBase(BufferOptions buffer_options,
-                                      ::tensorflow::Env* env)
-    : env_(env != nullptr ? env : ::tensorflow::Env::Default()),
+                                      tsl::Env* env)
+    : env_(env != nullptr ? env : tsl::Env::Default()),
       buffer_sizer_(buffer_options) {}
 
 inline FileWriterBase::FileWriterBase(FileWriterBase&& that) noexcept
@@ -288,17 +286,16 @@
   associated_reader_.Reset();
 }
 
-inline void FileWriterBase::Reset(BufferOptions buffer_options,
-                                  ::tensorflow::Env* env) {
+inline void FileWriterBase::Reset(BufferOptions buffer_options, tsl::Env* env) {
   Writer::Reset();
   // `filename_` will be set by `InitializeFilename()`.
-  env_ = env != nullptr ? env : ::tensorflow::Env::Default();
+  env_ = env != nullptr ? env : tsl::Env::Default();
   file_system_ = nullptr;
   buffer_sizer_.Reset(buffer_options);
   associated_reader_.Reset();
 }
 
-inline void FileWriterBase::Initialize(::tensorflow::WritableFile* dest) {
+inline void FileWriterBase::Initialize(tsl::WritableFile* dest) {
   RIEGELI_ASSERT_NE(dest, nullptr)
       << "Failed precondition of FileWriter: null WritableFile pointer";
   if (ABSL_PREDICT_FALSE(!InitializeFilename(dest))) return;
@@ -341,7 +338,7 @@
 inline void FileWriter<Dest>::Initialize(PathInitializer filename,
                                          Options&& options) {
   if (ABSL_PREDICT_FALSE(!InitializeFilename(std::move(filename)))) return;
-  std::unique_ptr<::tensorflow::WritableFile> dest = OpenFile(options.append());
+  std::unique_ptr<tsl::WritableFile> dest = OpenFile(options.append());
   if (ABSL_PREDICT_FALSE(dest == nullptr)) return;
   dest_.Reset(riegeli::Maker(dest.release()));
   InitializePos(dest_.get());
diff --git a/riegeli/tensorflow/io/tstring_writer.h b/riegeli/tensorflow/io/tstring_writer.h
index 1b88e3b..76cc993 100644
--- a/riegeli/tensorflow/io/tstring_writer.h
+++ b/riegeli/tensorflow/io/tstring_writer.h
@@ -25,15 +25,15 @@
 #include "riegeli/base/initializer.h"
 #include "riegeli/base/object.h"
 #include "riegeli/bytes/resizable_writer.h"
-#include "tensorflow/core/platform/tstring.h"
+#include "tensorflow/tsl/platform/tstring.h"
 
 namespace riegeli::tensorflow {
 
 namespace tstring_internal {
 
-// `ResizableTraits` for `tensorflow::tstring`.
+// `ResizableTraits` for `tsl::tstring`.
 struct TStringResizableTraits {
-  using Resizable = ::tensorflow::tstring;
+  using Resizable = tsl::tstring;
   static char* Data(Resizable& dest) { return dest.mdata(); }
   static size_t Size(const Resizable& dest) { return dest.size(); }
   static constexpr bool kIsStable = false;
@@ -68,7 +68,7 @@
     if (new_size > dest.capacity()) {
       dest.resize_uninitialized(used_size);
       dest.reserve(
-          dest.capacity() <= ::tensorflow::tstring().capacity()
+          dest.capacity() <= tsl::tstring().capacity()
               ? new_size
               : UnsignedMax(new_size, dest.capacity() + dest.capacity() / 2));
     }
@@ -80,30 +80,30 @@
 // Template parameter independent part of `TStringWriter`.
 using TStringWriterBase = ResizableWriterBase;
 
-// A `Writer` which writes to a `tensorflow::tstring`. If `Options::append()`
+// A `Writer` which writes to a `tsl::tstring`. If `Options::append()`
 // is `false` (the default), replaces existing contents of the
-// `tensorflow::tstring`, clearing it first. If `Options::append()` is `true`,
-// appends to existing contents of the `tensorflow::tstring`.
+// `tsl::tstring`, clearing it first. If `Options::append()` is `true`,
+// appends to existing contents of the `tsl::tstring`.
 //
 // It supports `Seek()` and `ReadMode()`.
 //
 // The `Dest` template parameter specifies the type of the object providing and
-// possibly owning the `tensorflow::tstring` being written to. `Dest` must
-// support `Dependency<tensorflow::tstring*, Dest>`, e.g.
-// `tensorflow::tstring*` (not owned,  default), `tensorflow::tstring` (owned),
-// `Any<tensorflow::tstring*>` (maybe owned).
+// possibly owning the `tsl::tstring` being written to. `Dest` must
+// support `Dependency<tsl::tstring*, Dest>`, e.g.
+// `tsl::tstring*` (not owned,  default), `tsl::tstring` (owned),
+// `Any<tsl::tstring*>` (maybe owned).
 //
 // By relying on CTAD the template argument can be deduced as
-// `tensorflow::tstring` if there are no constructor arguments or the only
+// `tsl::tstring` if there are no constructor arguments or the only
 // argument is `Options`, otherwise as `TargetT` of the type of the first
 // constructor argument, except that CTAD is deleted if the first constructor
-// argument is a `tensorflow::tstring&` or `const tensorflow::tstring&` (to
-// avoid writing to an unintentionally separate copy of an existing object).
+// argument is a `tsl::tstring&` or `const tsl::tstring&` (to avoid writing to
+// an unintentionally separate copy of an existing object).
 //
-// The `tensorflow::tstring` must not be accessed until the `TStringWriter` is
+// The `tsl::tstring` must not be accessed until the `TStringWriter` is
 // closed or no longer used, except that it is allowed to read the
-// `tensorflow::tstring` immediately after `Flush()`.
-template <typename Dest = ::tensorflow::tstring*>
+// `tsl::tstring` immediately after `Flush()`.
+template <typename Dest = tsl::tstring*>
 class TStringWriter
     : public ResizableWriter<tstring_internal::TStringResizableTraits, Dest> {
  public:
@@ -120,11 +120,11 @@
     -> TStringWriter<std::conditional_t<
         std::conjunction_v<std::is_lvalue_reference<Dest>,
                            std::is_convertible<std::remove_reference_t<Dest>*,
-                                               const ::tensorflow::tstring*>>,
+                                               const tsl::tstring*>>,
         DeleteCtad<Dest&&>, TargetT<Dest>>>;
 explicit TStringWriter(
     TStringWriterBase::Options options = TStringWriterBase::Options())
-    -> TStringWriter<::tensorflow::tstring>;
+    -> TStringWriter<tsl::tstring>;
 
 }  // namespace riegeli::tensorflow