Skip to content

use ape awk to replace gawk - #219

Open
comicfans wants to merge 1 commit into
bazel-contrib:mainfrom
comicfans:use_ape_awk
Open

comicfans wants to merge 1 commit into
bazel-contrib:mainfrom
comicfans:use_ape_awk

Conversation

@comicfans

Copy link
Copy Markdown

this allow creating sysroot that directly referenced by cc toolchain.

in my test I have following setup

apt.install(
    name = "jammy_x86_64_sysroot",
    lock = "//sysroot_creator:jammy_x86_64.lock.json",
    manifest = "//sysroot_creator:jammy_x86_64.yaml",
)
use_repo(apt, "jammy_x86_64_sysroot")

and

def _unpack_impl(ctx):
    out_dir = ctx.actions.declare_directory(ctx.label.name + "_unpacked")

    ctx.actions.run_shell(
        inputs = [ctx.file.tar],
        outputs = [out_dir],
        command = """ tar -xf {src} -C {out}""".format(src = ctx.file.tar.path, out = out_dir.path)
    )

    return [DefaultInfo(files = depset([out_dir]))]

unpack = rule(
    implementation = _unpack_impl,
    attrs = {
        "tar": attr.label(mandatory = True, allow_single_file = True)
    }
)

...

unpack(
    name = "jammy_unpack",
    tar = "@jammy_x86_64_sysroot//:jammy_x86_64_sysroot",  # or @jammy_x86_64_sysroot//:flat
    visibility = ["//visibility:public"]
)

# and jammy_unpack is used as cc toolchain sysroot

#124 (comment) mentioned that gawk is only used by flatten, however directly using @jammy_x86_64_sysroot//:jammy_x86_64_sysroot or @jammy_x86_64_sysroot//:flat as my unpack rule input trigger similar errors:

     @@rules_distroless++apt+jammy_x86_64_sysroot//:jammy_x86_64_sysroot (5c3ac65ce1c8329cc5f7202959c1aceda00db4bbc8a0148931c8e5ed92b61cf2)
    @@rules_distroless++apt+jammy_x86_64_sysroot//:jammy_x86_64_sysroot (fcc255dcd92f8a7c8464439d77cfb04da9617fbc87079de9a2f3462df62874c2)
    @@rules_distroless++apt+jammy_x86_64_sysroot//:dpkg_status (fcc255dcd92f8a7c8464439d77cfb04da9617fbc87079de9a2f3462df62874c2)
.-> @@gawk+//:gawk (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@bazel_tools//tools/cpp:current_cc_toolchain (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@rules_cc+//cc:current_cc_toolchain (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@toolchains_llvm++llvm+llvm_toolchain//:cc-clang-x86_64-linux (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@toolchains_llvm++llvm+llvm_toolchain//:module-x86_64-linux (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@toolchains_llvm++llvm+llvm_toolchain//:include-components-x86_64-linux (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@toolchains_llvm++llvm+llvm_toolchain//:sysroot-components-x86_64-linux (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   //sysroot_creator:jammy_unpack (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
|   @@rules_distroless++apt+jammy_x86_64_sysroot//:flat (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)
`-- @@gawk+//:gawk (38c6768e959f095860edbca0f0d106bbb7ba105ca378e880c8947a6ed3a0b464)

this allow creating sysroot that used by cc toolchain
@thesayyn

Copy link
Copy Markdown
Contributor

hmm whats the runtime cost here?

@comicfans

Copy link
Copy Markdown
Author

I use script in flatten.sh, input mtree is created by duplicate same file list twice, contains 5553536 lines, got following result:

ape              53.77s user 14.54s system 99% cpu 1:08.32 total
fastbuild_gawk   52.43s user 15.15s system 99% cpu 1:07.69 total
opt_gawk         33.76s user 13.70s system 99% cpu 47.631 total

ape is prebuilt so no differences between compilation_mode

@LittleHuba

LittleHuba commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@thesayyn for my work regarding sysroot support with rules_distroless I'd like to know if you prefer:

  1. this approach, or
  2. only shell commands and no awk at all.

Edit:
There is a third option:

  1. Leave all rules that are not used for sysroot support as they are and duplicate necessary logic in sysroot support without awk.

@LittleHuba

Copy link
Copy Markdown
Contributor

Unfortunate news:
ape awk requires a build action for conversion of the cosmopolitan binary into a native binary. This makes it unusable as part of a repository rule. So from what I can see this is not a viable path for sysroot creation.

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

Successfully merging this pull request may close these issues.

3 participants