bazelbuild / rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
https://bazelbuild.github.io/rules_foreign_cc
Apache License 2.0
649 stars 232 forks source link

Fetch rule in external cmake file leads to error in build #1123

Closed vymao closed 6 months ago

vymao commented 7 months ago

I am trying to build the following repo. I added it to my WORKSPACE as follows:

maybe(
        new_git_repository,
        name = "onnx_runtime_extensions",
        remote = "https://github.com/microsoft/onnxruntime-extensions.git",
        tag = "v0.9.0",
        build_file = Label("//external:BUILD.onnx_runtime_extensions")
    )

with the following BUILD file:

load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
    name = "all_srcs",
    srcs = glob(["**"]),
)

cc_library(
    name = "include",
    hdrs = glob(["includes/**"]),
    strip_include_prefix = "includes",
)

cmake(
    name = "onnx_extensions",
    lib_source = ":all_srcs",
    cache_entries = {
        "OCOS_ONNXRUNTIME_VERSION": "1.16.2",
    },
    visibility = ["//visibility:public"],
)

However, I get the following error:

+ /private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/cmake-3.26.4-macos-universal/bin/cmake -DOCOS_ONNXRUNTIME_PKG_URI=./onnxruntime-win-x64-1.16.0.zip -DOCOS_ONNXRUNTIME_VERSION=1.16.2 -DCMAKE_TOOLCHAIN_FILE=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions.build_tmpdir/crosstool_bazel.cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions '-DCMAKE_PREFIX_PATH=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions.ext_build_deps;external/onnx_runtime/include;bazel-out/darwin-fastbuild/bin/external/onnx_runtime/include' -DCMAKE_RANLIB= -G 'Unix Makefiles' /private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/onnx_runtime_extensions
-- The C compiler identification is AppleClang 15.0.0.15000038
-- The CXX compiler identification is AppleClang 15.0.0.15000038
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/local_config_cc/cc_wrapper.sh - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/local_config_cc/cc_wrapper.sh - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_SYSTEM_PROCESSOR=x86_64
-- CMAKE_GENERATOR_PLATFORM=
-- ONNX Runtime URL: https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz
[ 11%] Creating directories for 'onnxruntime-populate'
[ 22%] Performing download step (download, verify and extract) for 'onnxruntime-populate'
-- Downloading...
   dst='/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/38/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions.build_tmpdir/_deps/onnxruntime-subbuild/onnxruntime-populate-prefix/src/onnxruntime-osx-universal2-1.16.2.tgz'
   timeout='none'
   inactivity timeout='none'
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
-- Retrying...
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
-- Retry after 5 seconds (attempt #2) ...
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
-- Retry after 5 seconds (attempt #3) ...
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
-- Retry after 15 seconds (attempt #4) ...
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
-- Retry after 60 seconds (attempt #5) ...
-- Using src='https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz'
CMake Error at onnxruntime-subbuild/onnxruntime-populate-prefix/src/onnxruntime-populate-stamp/download-onnxruntime-populate.cmake:170 (message):
  Each download failed!

    error: downloading 'https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz' failed
          status_code: 7
          status_string: "Couldn't connect to server"
          log:
          --- LOG BEGIN ---
            Trying 140.82.114.3:443...

  Immediate connect fail for 140.82.114.3: Operation not permitted

I'm not sure why this is. I've verified that https://github.com/microsoft/onnxruntime/releases/download/v1.16.2/onnxruntime-osx-universal2-1.16.2.tgz can be downloaded simply via wget or curl, and I also built this repo outside of Bazel without any issue uising cmake version 3.27.7. The only issue I can point to is somehow through Bazel, and more specifically, the cmake rule here. This is a pain point because now I cannot build using Bazel here.

Wondering if this is the root cause?

vymao commented 7 months ago

If I run the actual command itself:

/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/cmake-3.26.4-macos-universal/bin/cmake 
-DOCOS_ONNXRUNTIME_PKG_URI=./onnxruntime-win-x64-1.16.0.zip -DOCOS_ONNXRUNTIME_VERSION=1.16.2 
-DCMAKE_TOOLCHAIN_FILE=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions.build_tmpdir/crosstool_bazel.cmake 
-DCMAKE_BUILD_TYPE=Release 
-DCMAKE_INSTALL_PREFIX=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions '
-DCMAKE_PREFIX_PATH=/private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/bazel-out/darwin-fastbuild/bin/external/onnx_runtime_extensions/onnx_extensions.ext_build_deps;external/onnx_runtime/include;bazel-out/darwin-fastbuild/bin/external/onnx_runtime/include' -DCMAKE_RANLIB= -G 'Unix Makefiles' /private/var/tmp/_bazel_victor/1cabe6594cc48c856544c639052f58cd/sandbox/darwin-sandbox/32/execroot/morris/external/onnx_runtime_extensions

In a separate directory, this proceeds without issue.

jsharpe commented 7 months ago

See the documentation for tags here: https://bazel.build/reference/be/common-definitions#common-attributes. You need to set the requires-network tag on your BUILD rule as Bazel's sandbox by default doesn't allow network access.