Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Compilation failure due to missing bazel platforms support #1573

Closed
gfrankliu opened this issue Nov 19, 2023 · 10 comments
Closed

[Bug]: Compilation failure due to missing bazel platforms support #1573

gfrankliu opened this issue Nov 19, 2023 · 10 comments
Assignees

Comments

@gfrankliu
Copy link

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:
#1210
#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

@derekmauro
Copy link
Member

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?

@gfrankliu
Copy link
Author

See my steps in f0rmiga/gcc-toolchain#155

@gfrankliu
Copy link
Author

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.

@derekmauro derekmauro self-assigned this Nov 29, 2023
@zhzhzoo-autra
Copy link

+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": [], 
})

@zhzhzoo-autra
Copy link

@derekmauro
Copy link
Member

+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.

@fmeum
Copy link

fmeum commented Jan 25, 2024

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

@derekmauro
Copy link
Member

derekmauro commented Jan 25, 2024

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?

@fmeum
Copy link

fmeum commented Jan 25, 2024

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.

@1e100
Copy link

1e100 commented Apr 30, 2024

Yeah, nobody can build absl-cpp with a recent Bazel without this. And nobody could for quite a while. Is this thing even alive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants