admin管理员组

文章数量:1404923

Is it possible to know about target platform constrains from-inside the transition implementation?

The problem comes from building a TensorFlow extension that apart from a few extra flags requires to transition to libstd if built on Linux. The main codebase is built with libc++ via LLVM.

Generally, I try to modify this code to fit multi-platform build: .bzl

Originally, it was written only for Linux. And attempt to extend it for macOS met an issue of conditioning those libstd lines on Linux only:

if (target_is_linux):
    cxxopts.append("-stdlib=libstdc++")
    linkopts.append("-stdlib=libstdc++")

What is the best way to approch it?

Bazel version: 7.5.0


Taking the transition is defined as inbound, I consider modifying the native_binary rule inside the [tf_custom_op_library]((.bzl#L111)) macros to execute a select on any of its attributes to resolve it before the transition invocation, and then access its value through atrs.

Although it seems to be the only way I've found so far, I wonder, if there is a better way? Or should the whole thing be redesigned for a milti-OS use? Or is there a way to pass constraints into transition as inputs?

本文标签: How to condition Bazel transition on target OSStack Overflow