From 9e03c6b248c489e27af692976d0457703dfc2935 Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Thu, 28 Sep 2023 21:58:21 -0700 Subject: [PATCH] add testing infra to sysroot creation (#23) Adds a test harness to help validate sysroot changes before publishing releases. --------- Co-authored-by: Matt Peddie --- .bazeliskrc | 1 + .bazelrc | 7 +++ .../workflows/bullseye-aarch64-sysroot.yaml | 22 +++++++- .../workflows/bullseye-x86_64-sysroot.yaml | 22 +++++++- .gitignore | 2 + BUILD.bazel | 0 WORKSPACE.bazel | 55 +++++++++++++++++++ sysroot/BUILD.bazel | 22 ++++++++ .../generated_package_lists/bullseye.amd64 | 4 ++ .../generated_package_lists/bullseye.arm64 | 4 ++ sysroot/sysroot-creator.sh | 4 ++ sysroot/test/lapack.cc | 42 ++++++++++++++ sysroot/test/uuid.cc | 8 +++ 13 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 .bazeliskrc create mode 100644 .bazelrc create mode 100644 BUILD.bazel create mode 100644 WORKSPACE.bazel create mode 100644 sysroot/BUILD.bazel create mode 100644 sysroot/test/lapack.cc create mode 100644 sysroot/test/uuid.cc diff --git a/.bazeliskrc b/.bazeliskrc new file mode 100644 index 0000000..afe0b46 --- /dev/null +++ b/.bazeliskrc @@ -0,0 +1 @@ +USE_BAZEL_VERSION=6.2.0 diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..10054a9 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,7 @@ +build:aarch64_sysroot --incompatible_enable_cc_toolchain_resolution +build:aarch64_sysroot --platforms=@rules_swiftnav//platforms:aarch64_bullseye_graviton2 + +build:x86_64_sysroot --incompatible_enable_cc_toolchain_resolution +build:x86_64_sysroot --@rules_swiftnav//cc:enable_sysroot=true + +try-import %workspace%/.bazelrc.user diff --git a/.github/workflows/bullseye-aarch64-sysroot.yaml b/.github/workflows/bullseye-aarch64-sysroot.yaml index 844cc37..5fee5c7 100644 --- a/.github/workflows/bullseye-aarch64-sysroot.yaml +++ b/.github/workflows/bullseye-aarch64-sysroot.yaml @@ -7,7 +7,7 @@ on: - .github/workflows/bullseye-aarch64-sysroot.yaml push: tags: - - "bullseye-aarch64-sysroot-*" + - "bullseye-sysroot-*" jobs: toolchains: @@ -21,6 +21,26 @@ jobs: run: ./sysroot/sysroot-creator.sh build arm64 - name: Upload sysroot + uses: actions/upload-artifact@v3 + with: + name: debian_bullseye_aarch64_sysroot.tar.xz + path: sysroot/out/sysroot-build/bullseye/debian_bullseye_arm64_sysroot.tar.xz + + - uses: bazelbuild/setup-bazelisk@v2 + + - name: Mount bazel cache + uses: actions/cache@v1 + with: + path: "~/.cache/bazel" + key: bazel + + - name: Copy sysroot + run: cp sysroot/out/sysroot-build/bullseye/debian_bullseye_arm64_sysroot.tar.xz debian_bullseye_aarch64_sysroot.tar.xz + + - name: Test sysroot + run: bazel build --config=aarch64_sysroot //sysroot/... + + - name: Release sysroot if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') uses: svenstaro/upload-release-action@v1-release with: diff --git a/.github/workflows/bullseye-x86_64-sysroot.yaml b/.github/workflows/bullseye-x86_64-sysroot.yaml index 1799b45..c6a634a 100644 --- a/.github/workflows/bullseye-x86_64-sysroot.yaml +++ b/.github/workflows/bullseye-x86_64-sysroot.yaml @@ -7,7 +7,7 @@ on: - .github/workflows/bullseye-x86_64-sysroot.yaml push: tags: - - "bullseye-x86_64-sysroot-*" + - "bullseye-sysroot-*" jobs: toolchains: @@ -21,6 +21,26 @@ jobs: run: ./sysroot/sysroot-creator.sh build amd64 - name: Upload sysroot + uses: actions/upload-artifact@v3 + with: + name: debian_bullseye_x86_64_sysroot.tar.xz + path: sysroot/out/sysroot-build/bullseye/debian_bullseye_amd64_sysroot.tar.xz + + - uses: bazelbuild/setup-bazelisk@v2 + + - name: Mount bazel cache + uses: actions/cache@v1 + with: + path: "~/.cache/bazel" + key: bazel + + - name: Copy sysroot + run: cp sysroot/out/sysroot-build/bullseye/debian_bullseye_amd64_sysroot.tar.xz debian_bullseye_x86_64_sysroot.tar.xz + + - name: Test sysroot + run: bazel build --config=x86_64_sysroot //sysroot/... + + - name: Release sysroot if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') uses: svenstaro/upload-release-action@v1-release with: diff --git a/.gitignore b/.gitignore index c2954e1..b024de7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ build-x86/ output/ llvm-obfuscator-*.txz sysroot/out +/bazel-* +.bazelrc.user diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 0000000..e69de29 diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel new file mode 100644 index 0000000..02d9b87 --- /dev/null +++ b/WORKSPACE.bazel @@ -0,0 +1,55 @@ +workspace(name = "swift-toolchains") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "bazel_skylib", + sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz", + ], +) + +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") + +bazel_skylib_workspace() + +http_archive( + name = "rules_swiftnav", + sha256 = "91a230cf400921189f1654ebe7ca10305e89f3d8cccc0c7486e6fc8886ac0d1b", + strip_prefix = "rules_swiftnav-3262a9ccd01951aa45576be3db102f03b84047eb", + url = "https://github.com/swift-nav/rules_swiftnav/archive/3262a9ccd01951aa45576be3db102f03b84047eb.tar.gz", +) + +load("@rules_swiftnav//cc:repositories.bzl", "register_swift_cc_toolchains", "swift_cc_toolchain") + +swift_cc_toolchain() + +register_swift_cc_toolchains() + +load("@rules_swiftnav//tools:local_archive.bzl", "local_archive") + +local_archive( + name = "aarch64-sysroot", + build_file_content = """ +filegroup( + name = "aarch64-sysroot", + srcs = glob(["*/**"]), + visibility = ["//visibility:public"], +) + """, + src = "//:debian_bullseye_aarch64_sysroot.tar.xz", +) + +local_archive( + name = "x86_64-sysroot", + build_file_content = """ +filegroup( + name = "x86_64-sysroot", + srcs = glob(["*/**"]), + visibility = ["//visibility:public"], +) + """, + src = "//:debian_bullseye_x86_64_sysroot.tar.xz", +) diff --git a/sysroot/BUILD.bazel b/sysroot/BUILD.bazel new file mode 100644 index 0000000..70caeee --- /dev/null +++ b/sysroot/BUILD.bazel @@ -0,0 +1,22 @@ +cc_binary( + name = "uuid", + srcs = ["test/uuid.cc"], + linkopts = [ + "-luuid", + ], +) + +cc_binary( + name = "foo", + srcs = ["test/lapack.cc"], + linkopts = [ + "-Lexternal/aarch64-sysroot/usr/lib/aarch64-linux-gnu/blas", + "-Lexternal/aarch64-sysroot/usr/lib/aarch64-linux-gnu/lapack", + "-Lexternal/x86_64-sysroot/usr/lib/x86_64-linux-gnu/blas", + "-Lexternal/x86_64-sysroot/usr/lib/x86_64-linux-gnu/lapack", + "-lm", + "-lpthread", + "-lblas", + "-llapack", + ], +) diff --git a/sysroot/generated_package_lists/bullseye.amd64 b/sysroot/generated_package_lists/bullseye.amd64 index 9cbed82..5516b5e 100644 --- a/sysroot/generated_package_lists/bullseye.amd64 +++ b/sysroot/generated_package_lists/bullseye.amd64 @@ -4,5 +4,9 @@ https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/gcc-10/l https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/gcc-10/libstdc++6_10.2.1-6_amd64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/glibc/libc6_2.31-13+deb11u5_amd64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/glibc/libc6-dev_2.31-13+deb11u5_amd64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/libblas3_3.9.0-3_amd64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/libblas-dev_3.9.0-3_amd64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/liblapack3_3.9.0-3_amd64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/liblapack-dev_3.9.0-3_amd64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/linux/linux-libc-dev_6.1.12-1~bpo11+1_amd64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/u/util-linux/uuid-dev_2.36.1-8+deb11u1_amd64.deb diff --git a/sysroot/generated_package_lists/bullseye.arm64 b/sysroot/generated_package_lists/bullseye.arm64 index ebe6feb..5e6152c 100644 --- a/sysroot/generated_package_lists/bullseye.arm64 +++ b/sysroot/generated_package_lists/bullseye.arm64 @@ -4,5 +4,9 @@ https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/gcc-10/l https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/gcc-10/libstdc++6_10.2.1-6_arm64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/glibc/libc6_2.31-13+deb11u5_arm64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/g/glibc/libc6-dev_2.31-13+deb11u5_arm64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/libblas3_3.9.0-3_arm64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/libblas-dev_3.9.0-3_arm64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/liblapack3_3.9.0-3_arm64.deb +https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/lapack/liblapack-dev_3.9.0-3_arm64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/l/linux/linux-libc-dev_6.1.12-1~bpo11+1_arm64.deb https://snapshot.debian.org/archive/debian/20230329T085712Z/pool/main/u/util-linux/uuid-dev_2.36.1-8+deb11u1_arm64.deb diff --git a/sysroot/sysroot-creator.sh b/sysroot/sysroot-creator.sh index 228f2ce..ad76898 100755 --- a/sysroot/sysroot-creator.sh +++ b/sysroot/sysroot-creator.sh @@ -61,6 +61,10 @@ DEBIAN_PACKAGES="\ uuid-dev libgcc-10-dev libgcc-s1 + libblas-dev + libblas3 + liblapack-dev + liblapack3 " DEBIAN_PACKAGES_AMD64=" diff --git a/sysroot/test/lapack.cc b/sysroot/test/lapack.cc new file mode 100644 index 0000000..4e8f99d --- /dev/null +++ b/sysroot/test/lapack.cc @@ -0,0 +1,42 @@ +// LAPACK test code +//compile with: g++ main.cpp -llapack -lblas -o testprog + +#include +#include + +using namespace std; + +extern "C" void dgetrf_(int* dim1, int* dim2, double* a, int* lda, int* ipiv, int* info); +extern "C" void dgetrs_(char *TRANS, int *N, int *NRHS, double *A, int *LDA, int *IPIV, double *B, int *LDB, int *INFO ); + +int main() +{ + char trans = 'N'; + int dim = 2; + int nrhs = 1; + int LDA = dim; + int LDB = dim; + int info; + + vector a, b; + + a.push_back(1); + a.push_back(1); + a.push_back(1); + a.push_back(-1); + + b.push_back(2); + b.push_back(0); + + int ipiv[3]; + + dgetrf_(&dim, &dim, &*a.begin(), &LDA, ipiv, &info); + dgetrs_(&trans, &dim, &nrhs, & *a.begin(), &LDA, ipiv, & *b.begin(), &LDB, &info); + + + std::cout << "solution is:"; + std::cout << "[" << b[0] << ", " << b[1] << ", " << "]" << std::endl; + std::cout << "Info = " << info << std::endl; + + return(0); +} diff --git a/sysroot/test/uuid.cc b/sysroot/test/uuid.cc new file mode 100644 index 0000000..b94827d --- /dev/null +++ b/sysroot/test/uuid.cc @@ -0,0 +1,8 @@ +#include +#include + +int main() { + uuid_t uuid{}; + uuid_generate_random(uuid); + std::cout << "uuid: " << uuid << std::endl; +}