Skip to content

Commit

Permalink
feat(build): cross build for amazonlinux:2 x86_64
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion authored and AndyZhang0707 committed Jul 23, 2024
1 parent e67b7e0 commit 5d2434c
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/matrix-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ build-packages:

# Amazon Linux
- label: amazonlinux-2
image: amazonlinux:2
package: rpm
package-type: aws2
check-manifest-suite: amazonlinux-2-amd64
bazel-args: --platforms=//:aws2-crossbuild-x86_64
- label: amazonlinux-2023
image: amazonlinux:2023
package: rpm
Expand Down
21 changes: 21 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ platform(
for vendor in aarch64_glibc_distros
]

platform(
name = "aws2-crossbuild-x86_64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
"//build/platforms/distro:aws2",
":cross_build",
],
)

# config_settings define a select() condition based on user-set constraint_values
# see https://bazel.build/docs/configurable-attributes
config_setting(
Expand All @@ -218,12 +228,23 @@ config_setting(
visibility = ["//visibility:public"],
)

config_setting(
name = "x86_64-linux-anylibc-cross",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
":cross_build",
],
visibility = ["//visibility:public"],
)

selects.config_setting_group(
# matches all cross build platforms
name = "any-cross",
match_any = [
":aarch64-linux-anylibc-cross",
":x86_64-linux-musl-cross",
":x86_64-linux-anylibc-cross",
],
visibility = ["//visibility:public"],
)
8 changes: 8 additions & 0 deletions build/toolchain/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ define_managed_toolchain(
vendor = "alpine",
)

define_managed_toolchain(
arch = "x86_64",
gcc_version = aarch64_glibc_distros["aws2"],
libc = "gnu",
target_compatible_with = ["//build/platforms/distro:aws2"],
vendor = "aws2",
)

[
define_managed_toolchain(
arch = "aarch64",
Expand Down
21 changes: 21 additions & 0 deletions build/toolchain/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ def _cc_toolchain_config_impl(ctx):
tools_path_prefix = ctx.attr.tools_path_prefix
compiler_configuration = ctx.attr.compiler_configuration

# update to absolute paths if we are using a managed toolchain (downloaded by bazel)
if len(ctx.files.src) > 0:
if toolchain_path_prefix:
fail("Both `src` and `toolchain_path_prefix` is set, but toolchain_path_prefix will be overrided if `src` is set.")

# file is something like external/aarch64-rhel9-linux-gnu-gcc-11/aarch64-rhel9-linux-gnu/bin/ar
# we will take aarch64-rhel9-linux-gnu-gcc-11/aarch64-rhel9-linux-gnu
ar_path = None
for f in ctx.files.src:
if f.path.endswith("bin/ar"):
ar_path = f.path
break
if not ar_path:
fail("Cannot find ar in the toolchain")
toolchain_path_prefix = INTERNAL_ROOT + "/" + "/".join(ar_path.split("/")[1:3])

_tools_root_dir = INTERNAL_ROOT + "/" + ctx.files.src[0].path.split("/")[1]
tools_prefix = _tools_root_dir + "/bin/" + tools_prefix
else:
tools_prefix = "/usr/bin/" + tools_prefix

# Unfiltered compiler flags; these are placed at the end of the command
# line, so take precendence over any user supplied flags through --copts or
# such.
Expand Down
7 changes: 7 additions & 0 deletions build/toolchain/managed_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ def register_all_toolchains(name = None):
vendor = "alpine",
)

register_managed_toolchain(
arch = "x86_64",
gcc_version = "7",
libc = "gnu",
vendor = "aws2",
)

for vendor in aarch64_glibc_distros:
register_managed_toolchain(
arch = "aarch64",
Expand Down
8 changes: 8 additions & 0 deletions build/toolchain/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,11 @@ def toolchain_repositories():
strip_prefix = "aarch64-aws2-linux-gnu",
build_file_content = build_file_content,
)

http_archive(
name = "x86_64-aws2-linux-gnu-gcc-7",
url = "https://github.com/Kong/crosstool-ng-actions/releases/download/0.7.0/x86_64-aws2-linux-gnu-glibc-2.26-gcc-7.tar.gz",
sha256 = "645c242d13bf456ca59a7e9701e9d2f53336fd0497ccaff2b151da9921469985",
strip_prefix = "x86_64-aws2-linux-gnu",
build_file_content = build_file_content,
)
16 changes: 6 additions & 10 deletions scripts/explain_manifest/fixtures/amazonlinux-2-amd64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,43 @@

- Path : /usr/local/kong/lib/engines-1.1/afalg.so
Needed :
- libstdc++.so.6
- libm.so.6
- libcrypto.so.1.1
- libdl.so.2
- libc.so.6
Runpath : /usr/local/kong/lib
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/engines-1.1/capi.so
Needed :
- libstdc++.so.6
- libm.so.6
- libcrypto.so.1.1
- libdl.so.2
- libc.so.6
Runpath : /usr/local/kong/lib
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/engines-1.1/padlock.so
Needed :
- libstdc++.so.6
- libm.so.6
- libcrypto.so.1.1
- libdl.so.2
- libc.so.6
Runpath : /usr/local/kong/lib
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libcrypto.so.1.1
Needed :
- libstdc++.so.6
- libm.so.6
- libstdc++.so.6
- libdl.so.2
- libc.so.6
Runpath : /usr/local/kong/lib
Rpath : /usr/local/kong/lib

- Path : /usr/local/kong/lib/libssl.so.1.1
Needed :
- libstdc++.so.6
- libm.so.6
- libcrypto.so.1.1
- libdl.so.2
- libc.so.6
Runpath : /usr/local/kong/lib
Rpath : /usr/local/kong/lib

- Path : /usr/local/lib/lua/5.1/lfs.so
Needed :
Expand Down

0 comments on commit 5d2434c

Please sign in to comment.