Open gfrankliu opened 11 months ago
Steps to reproduce the problem
Use bazel "platforms" to cross compile for non-x86 target, you will see the errors.
I don't doubt that something doesn't work. Can you give us an example command?
See my steps in https://github.com/aspect-build/gcc-toolchain/issues/155
To reproduce, use the cross compiler from aspect-build gcc-toolchain which uses the new bazel platforms.
git clone https://github.com/abseil/abseil-cpp.git
cd abseil-cpp/
cat >> WORKSPACE << EOF
# aspect-build
http_archive(
name = "aspect_gcc_toolchain",
sha256 = "3341394b1376fb96a87ac3ca01c582f7f18e7dc5e16e8cf40880a31dd7ac0e1e",
strip_prefix = "gcc-toolchain-0.4.2",
url = "https://github.com/aspect-build/gcc-toolchain/archive/refs/tags/0.4.2.tar.gz",
)
load("@aspect_gcc_toolchain//toolchain:defs.bzl", "gcc_register_toolchain", "ARCHS")
gcc_register_toolchain(
name = "gcc_toolchain_aarch64",
sysroot_variant = "aarch64",
target_arch = ARCHS.aarch64,
)
gcc_register_toolchain(
name = "gcc_toolchain_x86_64",
sysroot_variant = "x86_64",
target_arch = ARCHS.x86_64,
)
EOF
bazel build //absl/random --incompatible_enable_cc_toolchain_resolution --platforms=@aspect_gcc_toolchain//platforms:aarch64_linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
You should see the errors because the cpu type was not properly selected.
+1 for this, the problem is in absl/copts/configure_copts.bzl
# ABSL_RANDOM_RANDEN_COPTS blaze copts flags which are required by each
# environment to build an accelerated RandenHwAes library.
ABSL_RANDOM_RANDEN_COPTS = select({
# APPLE
":cpu_darwin_x86_64": ABSL_RANDOM_HWAES_X64_FLAGS,
":cpu_darwin": ABSL_RANDOM_HWAES_X64_FLAGS,
":cpu_x64_windows_msvc": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS,
":cpu_x64_windows": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS,
":cpu_k8": ABSL_RANDOM_HWAES_X64_FLAGS,
":cpu_ppc": ["-mcrypto"],
":cpu_aarch64": ABSL_RANDOM_HWAES_ARM64_FLAGS,
# Supported by default or unsupported.
"//conditions:default": [],
})
if using platforms this should be written:
select({
"@platforms//cpu:k8": ABSL_RANDOM_HWAES_X64_FLAGS,
"@platforms//cpu:ppc": ["-mcrypto"],
"@platforms//cpu:aarch64": ABSL_RANDOM_HWAES_ARM64_FLAGS,
# blabla...
# Supported by default or unsupported.
"//conditions:default": [],
})
+1 for this, the problem is in
absl/copts/configure_copts.bzl
# ABSL_RANDOM_RANDEN_COPTS blaze copts flags which are required by each # environment to build an accelerated RandenHwAes library. ABSL_RANDOM_RANDEN_COPTS = select({ # APPLE ":cpu_darwin_x86_64": ABSL_RANDOM_HWAES_X64_FLAGS, ":cpu_darwin": ABSL_RANDOM_HWAES_X64_FLAGS, ":cpu_x64_windows_msvc": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS, ":cpu_x64_windows": ABSL_RANDOM_HWAES_MSVC_X64_FLAGS, ":cpu_k8": ABSL_RANDOM_HWAES_X64_FLAGS, ":cpu_ppc": ["-mcrypto"], ":cpu_aarch64": ABSL_RANDOM_HWAES_ARM64_FLAGS, # Supported by default or unsupported. "//conditions:default": [], })
if using platforms this should be written:
select({ "@platforms//cpu:k8": ABSL_RANDOM_HWAES_X64_FLAGS, "@platforms//cpu:ppc": ["-mcrypto"], "@platforms//cpu:aarch64": ABSL_RANDOM_HWAES_ARM64_FLAGS, # blabla... # Supported by default or unsupported. "//conditions:default": [], })
The proposed solution doesn't support MSVC. It makes the assumption that all compilers for that CPU support the GCC-style flags.
The correct solution is to use the settings in this file instead of OS settings (plus @platforms//cpu
constraints if necessary):
https://github.com/bazelbuild/rules_cc/blob/main/cc/compiler/BUILD
The correct solution is to use the settings in this file instead of OS settings (plus
@platforms//cpu
constraints if necessary): https://github.com/bazelbuild/rules_cc/blob/main/cc/compiler/BUILD
Yes, that is part of the solution. How do I get the cross product of compiler and cpu?
Yes, that is part of the solution. How do I get the cross product of compiler and cpu?
One option would be to use skylib's selects.config_setting_group to define selectable targets for each combination in the cross product.
Yeah, nobody can build absl-cpp with a recent Bazel without this. And nobody could for quite a while. Is this thing even alive?
Describe the issue
bazel is migrating to use the new "platforms" to support multi architectures: https://bazel.build/concepts/platforms
As more and more people start to use the new bazel and the platforms rules, we will see more compilation errors such as: https://github.com/abseil/abseil-cpp/issues/1210 https://github.com/abseil/abseil-cpp/issues/1227
Can abseil update to support that?
Steps to reproduce the problem
Use bazel "platforms" to cross compile for non-x86 target, you will see the errors.
What version of Abseil are you using?
latest as of Nov 19, 2023.
What operating system and version are you using?
Host Debian 12 am64, target arm64.
What compiler and version are you using?
gcc cross compiler.
What build system are you using?
bazel 6.4.0
Additional context
No response