diff --git a/.github/workflows/ubuntu_basic.yml b/.github/workflows/ubuntu_basic.yml index 48a2939..b40d3f4 100644 --- a/.github/workflows/ubuntu_basic.yml +++ b/.github/workflows/ubuntu_basic.yml @@ -2,23 +2,36 @@ name: ubuntu-basic on: push: - branches: [ main ] + branches: + - main + - fix-build-onpy11 pull_request: - branches: [ main ] + branches: + - main + - fix-build-onpy11 jobs: run-unit-tests: timeout-minutes: 60 runs-on: ubuntu-latest - container: docker.io/library/ubuntu:22.04 + container: docker.io/library/ubuntu:latest steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: '3.11' - name: Install bazel run: | apt-get update + export DEBIAN_FRONTEND=noninteractive + apt-get install -y software-properties-common add-apt-repository ppa:deadsnakes/ppa + apt-get install -y git cmake apt-get install -yq wget gcc g++ python3.11 zlib1g-dev zip libuv1.dev apt-get install -yq pip diff --git a/WORKSPACE b/WORKSPACE index c860bd1..1b8f3f3 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,16 +1,16 @@ workspace(name = "pygloo") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") -# Group the sources of the library so that CMake rule have access to it -all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""" - +# --- Python Rules --- http_archive( name = "rules_python", + sha256 = "3b8b4cdc991bc9def8833d118e4c850f1b7498b3d65d5698eea92c3528b8cf2c", strip_prefix = "rules_python-0.30.0", - url = "https://wq-boost.oss-cn-beijing.aliyuncs.com/rules_python-0.30.0.tar.gz", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.30.0/rules_python-0.30.0.tar.gz", ) -# if missing it will trig the error message of the OP + load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") py_repositories() @@ -20,7 +20,7 @@ python_register_toolchains( ignore_root_user_error = True, ) -# Rule repository +# --- Foreign CC Rules (for CMake/Make) --- http_archive( name = "rules_foreign_cc", strip_prefix = "rules_foreign_cc-87df6b25f6c009883da87f07ea680d38780a4d6f", @@ -29,32 +29,9 @@ http_archive( ) load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies") - -# Call this function from the WORKSPACE file to initialize rules_foreign_cc -# dependencies and let neccesary code generation happen -# (Code generation is needed to support different variants of the C++ Starlark API.). -# -# Args: -# native_tools_toolchains: pass the toolchains for toolchain types -# '@rules_foreign_cc//tools/build_defs:make_toolchain', -# '@rules_foreign_cc//tools/build_defs:cmake_toolchain' and -# '@rules_foreign_cc//tools/build_defs:ninja_toolchain' with the needed platform constraints. -# If you do not pass anything, registered default toolchains will be selected (see below). -# -# register_default_tools: if True, the make, cmake and ninja toolchains, calling corresponding -# preinstalled binaries by name (make, cmake, ninja) will be registered after -# 'native_tools_toolchains' without any platform constraints. -# The default is True. rules_foreign_cc_dependencies() - -http_archive( - name = "rules_foreign_cc", - strip_prefix = "opencensus-proto-0.3.0/src", - urls = ["https://github.com/census-instrumentation/opencensus-proto/archive/v0.3.0.tar.gz"], - sha256 = "b7e13f0b4259e80c3070b583c2f39e53153085a6918718b1c710caf7037572b0", -) - +# --- Pybind11 --- http_archive( name = "pybind11_bazel", strip_prefix = "pybind11_bazel-2.13.6", @@ -62,16 +39,17 @@ http_archive( sha256 = "9df284330336958c837fb70dc34c0a6254dac52a5c983b3373a8c2bbb79ac35e", ) -# We still require the pybind library. http_archive( - name = "pybind11", - build_file = "@pybind11_bazel//:pybind11-BUILD.bazel", - strip_prefix = "pybind11-2.13.6", - # urls = ["https://github.com/pybind/pybind11/archive/v2.13.6.zip"], - urls = ["https://wq-boost.oss-cn-beijing.aliyuncs.com/pybind11-2.13.6.zip"], - # sha256 = "cdbe326d357f18b83d10322ba202d69f11b2f49e2d87ade0dc2be0c5c34f8e2a", + name = "pybind11", + build_file = "@pybind11_bazel//:pybind11-BUILD.bazel", + sha256 = "d0a116e91f64a4a2d8fb7590c34242df92258a61ec644b79127951e821b47be6", + strip_prefix = "pybind11-2.13.6", + urls = ["https://github.com/pybind/pybind11/archive/refs/tags/v2.13.6.zip"], ) +# --- Other C++ Dependencies (using the old `all_content` method as they are not CMake projects) --- +all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])""" + http_archive( name = "libuv", build_file_content = all_content, @@ -88,16 +66,39 @@ http_archive( sha256 = "2a0b5fe5119ec973a0c1966bfc4bd7ed39dbce1cb6d749064af9121fe971936f", ) -# gloo source code repository -http_archive( - name = "gloo", - build_file_content = all_content, - strip_prefix = "gloo-add3f38c6a2715e9387f4966b4fc3d92bb786adb", - urls = ["https://github.com/Ezra-H/gloo/archive/add3f38c6a2715e9387f4966b4fc3d92bb786adb.tar.gz"], - sha256 = "a146136bb6efdac0e3ede952d09aec44b771a87ebc713bd815c3a90a7428c908", +# --- Gloo Dependency (Corrected Method) --- +git_repository( + name = "gloo", + remote = "https://github.com/pytorch/gloo.git", + commit = "c37d821", + # We inject a BUILD.bazel file to tell Bazel how to build this CMake project. + build_file_content = """ +load("@rules_foreign_cc//tools/build_defs:cmake.bzl", "cc_cmake") + +# Define a filegroup to capture all source files. +filegroup( + name = "all_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], ) -# load("@pybind11_bazel//:python_configure.bzl", "python_configure_pybind") -# python_configure_pybind(name = "local_config_python") - +# Define the rule to build the external CMake project. +cc_cmake( + name = "gloo_lib", + lib_source = ":all_srcs", + out_static_libs = ["libgloo.a"], + options = [ + "-DBUILD_TEST=OFF", + "-DBUILD_BENCHMARK=OFF", + ], + visibility = ["//visibility:public"], +) +# Create an alias so that other targets can depend on @gloo//:all as before. +alias( + name = "all", + actual = ":gloo_lib", + visibility = ["//visibility:public"], +) +""", +)