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

Making bsdtar and coreutils fully portable for amd64 #732

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions lib/private/coreutils_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ COREUTILS_VERSIONS = {
},
}

COREUTILS_DEPS = {
"0.0.23": {
"linux_amd64": [
# https://packages.ubuntu.com/focal/amd64/libgcc1/download
(
"be48e8f4b1cb8bbdd642966bfcc08b119a7c8317b807bce6bf8da35817468d06",
"http://security.ubuntu.com/ubuntu/pool/universe/g/gcc-10/libgcc1_10.5.0-1ubuntu1~20.04_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libc6/download
(
"a469164a97599aaef2552512acfd91c8830dc8d5e8053f9c02215ff9cd36673c",
"http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.31-0ubuntu9.14_amd64.deb",
),
],
},
}

CoreUtilsInfo = provider(
doc = "Provide info for executing coreutils",
fields = {
Expand All @@ -81,7 +98,7 @@ def _coreutils_toolchain_impl(ctx):
"COREUTILS_BIN": binary.path,
})
default_info = DefaultInfo(
files = depset([binary]),
files = depset([binary] + ctx.files.files),
runfiles = ctx.runfiles(files = [binary]),
)
coreutils_info = CoreUtilsInfo(
Expand All @@ -105,6 +122,7 @@ coreutils_toolchain = rule(
mandatory = True,
allow_single_file = True,
),
"files": attr.label_list(allow_files = True),
},
)

Expand Down Expand Up @@ -185,11 +203,42 @@ def _coreutils_platform_repo_impl(rctx):
stripPrefix = filename.replace(".zip", "").replace(".tar.gz", ""),
integrity = COREUTILS_VERSIONS[rctx.attr.version][platform]["sha256"],
)

deps = COREUTILS_DEPS.get(rctx.attr.version, {}).get(platform, [])

binary = "coreutils.exe" if is_windows else "coreutils"

if deps:
for dep in deps:
rctx.download_and_extract(
url = dep[1],
type = "deb",
sha256 = dep[0],
)

rctx.extract("data.tar.xz")

# Other platforms, we have more work to do.
usr_libs_dir = "usr/lib/x86_64-linux-gnu" if rctx.attr.platform.endswith("amd64") else "usr/lib/aarch64-linux-gnu"
libs_dir = "lib/x86_64-linux-gnu" if rctx.attr.platform.endswith("amd64") else "lib/aarch64-linux-gnu"
linker = "lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" if rctx.attr.platform.endswith("amd64") else "lib/aarch64-linux-gnu/ld-linux-aarch64.so.2"

rctx.file("coreutils.sh", """#!/usr/bin/env bash
readonly wksp="$(dirname "${{BASH_SOURCE[0]}}")"
LD_LIBRARY_PATH=$wksp/{libs_dir}:$wksp/lib:$wksp/{usr_libs_dir} exec $wksp/{linker} $wksp/coreutils $@
""".format(name = rctx.name, libs_dir = libs_dir, usr_libs_dir = usr_libs_dir, linker = linker))
binary = "coreutils.sh"

build_content = """# @generated by @aspect_bazel_lib//lib/private:coreutils_toolchain.bzl
load("@aspect_bazel_lib//lib/private:coreutils_toolchain.bzl", "coreutils_toolchain")
exports_files(["{0}"])
coreutils_toolchain(name = "coreutils_toolchain", binary = "{0}", visibility = ["//visibility:public"])
""".format("coreutils.exe" if is_windows else "coreutils")
coreutils_toolchain(
name = "coreutils_toolchain",
binary = "{0}",
files = glob(["**/*.so.*"]) + ["{0}"],
visibility = ["//visibility:public"]
)
""".format(binary)

# Base BUILD file for this repository
rctx.file("BUILD.bazel", build_content)
Expand Down
47 changes: 42 additions & 5 deletions lib/private/tar_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ LINUX_LIB_DEPS = {
"00d0de456134668f41bd9ea308a076bc0a6a805180445af8a37209d433f41efe",
"http://security.ubuntu.com/ubuntu/pool/main/i/icu/libicu66_66.1-2ubuntu2.1_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libc6/download
(
"a469164a97599aaef2552512acfd91c8830dc8d5e8053f9c02215ff9cd36673c",
"http://security.ubuntu.com/ubuntu/pool/main/g/glibc/libc6_2.31-0ubuntu9.14_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libacl1/download
(
"9fa9cc2f8eeccd8d29efcb998111b082432c65de75ca60ad9c333289bb3bb765",
"http://security.ubuntu.com/ubuntu/pool/main/a/acl/libacl1_2.2.53-6_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/liblzma5/download
(
"f545d34c86119802fbae869a09e1077a714e12a01ef6a3ef67fdc745e5db311d",
"http://security.ubuntu.com/ubuntu/pool/main/x/xz-utils/liblzma5_5.2.4-1ubuntu1.1_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libstdc++6/download
(
"7f9222342d3551d063bf651319ec397c39278eeeb9ab5950ae0e8c28ef0af431",
"http://security.ubuntu.com/ubuntu/pool/main/g/gcc-10/libstdc++6_10.5.0-1ubuntu1~20.04_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libgcc1/download
(
"be48e8f4b1cb8bbdd642966bfcc08b119a7c8317b807bce6bf8da35817468d06",
"http://security.ubuntu.com/ubuntu/pool/universe/g/gcc-10/libgcc1_10.5.0-1ubuntu1~20.04_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libzstd1/download
(
"7a4422dadb90510dc90765c308d65e61a3e244ceb3886394335e48cff7559e69",
"http://security.ubuntu.com/ubuntu/pool/main/libz/libzstd/libzstd1_1.4.4+dfsg-3ubuntu0.1_amd64.deb",
),
# https://packages.ubuntu.com/focal/amd64/libbz2-1.0/download
(
"f3632ec38402ca0f9c61a6854469f1a0eba9389d3f73827b466033c3d5bbec69",
"http://security.ubuntu.com/ubuntu/pool/main/b/bzip2/libbz2-1.0_1.0.8-2_amd64.deb",
),
],
}

Expand Down Expand Up @@ -138,7 +173,9 @@ package(default_visibility = ["//visibility:public"])
return

# Other platforms, we have more work to do.
libs_dir = "usr/lib/x86_64-linux-gnu" if rctx.attr.platform.endswith("amd64") else "usr/lib/aarch64-linux-gnu"
usr_libs_dir = "usr/lib/x86_64-linux-gnu" if rctx.attr.platform.endswith("amd64") else "usr/lib/aarch64-linux-gnu"
libs_dir = "lib/x86_64-linux-gnu" if rctx.attr.platform.endswith("amd64") else "lib/aarch64-linux-gnu"
linker = "lib/x86_64-linux-gnu/ld-linux-x86-64.so.2" if rctx.attr.platform.endswith("amd64") else "lib/aarch64-linux-gnu/ld-linux-aarch64.so.2"

for lib in LINUX_LIB_DEPS[rctx.attr.platform]:
rctx.download_and_extract(
Expand All @@ -150,17 +187,17 @@ package(default_visibility = ["//visibility:public"])

rctx.file("bsdtar.sh", """#!/usr/bin/env bash
readonly wksp="$(dirname "${{BASH_SOURCE[0]}}")"
LD_LIBRARY_PATH=$wksp/{libs_dir} exec $wksp/usr/bin/bsdtar $@
""".format(name = rctx.name, libs_dir = libs_dir))
LD_LIBRARY_PATH=$wksp/{libs_dir}:$wksp/lib:$wksp/{usr_libs_dir} exec $wksp/{linker} $wksp/usr/bin/bsdtar $@
""".format(name = rctx.name, libs_dir = libs_dir, usr_libs_dir = usr_libs_dir, linker = linker))

rctx.file("BUILD.bazel", build_header + """\
tar_toolchain(
name = "bsdtar_toolchain",
files = glob(["{libs}/*.so.*"]) + ["usr/bin/bsdtar"],
files = glob(["**/*.so.*"]) + ["usr/bin/bsdtar"],
binary = "bsdtar.sh",
visibility = ["//visibility:public"],
)
""".format(libs = libs_dir, name = rctx.name))
""".format(name = rctx.name))

bsdtar_binary_repo = repository_rule(
implementation = _bsdtar_binary_repo,
Expand Down