Skip to content

Commit

Permalink
Use new linker input API
Browse files Browse the repository at this point in the history
This bumps our minimum bazel version requirement to v3.0.0.
See bazelbuild/bazel#10860.

Also, update some other bazel dependencies we use in our tests.

Updated bazelisk can use GCS as a fallback when github returns an error,
which means we don't have to use a github API token anymore, which were
never available for pull requests anyway.
  • Loading branch information
siddharthab committed Mar 17, 2021
1 parent 8b89650 commit 70cd564
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 64 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ jobs:
run: sudo apt-get install libcurl4-openssl-dev

- name: Run tests
env:
BAZELISK_GITHUB_TOKEN: ${{ secrets.BAZELISK_GITHUB_TOKEN }}
run: tests/run_tests.sh
2 changes: 1 addition & 1 deletion R/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ load(
r_coverage_dependencies = _r_coverage_dependencies

def r_rules_dependencies():
_is_at_least("1.0.0", native.bazel_version)
_is_at_least("3.0.0", native.bazel_version)

# TODO: Use bazel-skylib directly instead of replicating functionality when
# nested workspaces become a reality. Otherwise, dependencies will need to
Expand Down
70 changes: 32 additions & 38 deletions R/internal/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -80,49 +80,43 @@ def _strip_path_prefixes(iterable, p1, p2):

def _link_info(dep, root_path):
# Returns libraries to link from a cc_dep, giving preference to PIC.

linking_context = dep[CcInfo].linking_context
libraries_to_link = linking_context.libraries_to_link
user_link_flags = linking_context.user_link_flags
libs = []
c_so_files = []
c_libs_flags = list(user_link_flags)
c_libs_flags_short = list(user_link_flags)

# https://github.com/bazelbuild/bazel/issues/8118
# TODO: Simplify when we don't support bazel 0.26.
if hasattr(linking_context.libraries_to_link, "to_list"):
libraries_to_link = linking_context.libraries_to_link.to_list()
else:
libraries_to_link = linking_context.libraries_to_link

for library_to_link in libraries_to_link:
if library_to_link.pic_static_library != None:
l = library_to_link.pic_static_library
elif library_to_link.static_library != None:
l = library_to_link.static_library
elif library_to_link.interface_library != None:
l = library_to_link.interface_library
elif library_to_link.dynamic_library != None:
l = library_to_link.dynamic_library
else:
fail("unreachable")

libs.append(l)

# dylib is not supported because macOS does not support $ORIGIN in rpath.
if l.extension == "so":
c_so_files.append(l)

# We copy the file in srcs and set relative rpath for R CMD INSTALL.
c_libs_flags.append(l.basename)
c_libs_flags = []
c_libs_flags_short = []

# We use LD_LIBRARY_PATH for R CMD check.
linker_inputs = dep[CcInfo].linking_context.linker_inputs.to_list()
for linker_input in linker_inputs:
for library_to_link in linker_input.libraries:
if library_to_link.pic_static_library != None:
l = library_to_link.pic_static_library
elif library_to_link.static_library != None:
l = library_to_link.static_library
elif library_to_link.interface_library != None:
l = library_to_link.interface_library
elif library_to_link.dynamic_library != None:
l = library_to_link.dynamic_library
else:
fail("unreachable")

libs.append(l)

# dylib is not supported because macOS does not support $ORIGIN in rpath.
if l.extension == "so":
c_so_files.append(l)

# We copy the file in srcs and set relative rpath for R CMD INSTALL.
c_libs_flags.append(l.basename)

# We use LD_LIBRARY_PATH for R CMD check.
c_libs_flags_short.append(root_path + l.short_path)
continue

c_libs_flags.append(root_path + l.path)
c_libs_flags_short.append(root_path + l.short_path)
continue

c_libs_flags.append(root_path + l.path)
c_libs_flags_short.append(root_path + l.short_path)
c_libs_flags.extend(linker_input.user_link_flags)
c_libs_flags_short.extend(linker_input.user_link_flags)

return struct(
c_libs_flags = c_libs_flags,
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ GRAIL to build 400+ R packages from CRAN and Bioconductor.

The following assumes that you are familiar with how to use Bazel in general.

In order to use the rules, you must have bazel 1.0.0 or later and add the
following to your WORKSPACE file:
To begin, you can add the following or equivalent to your WORKSPACE file:

```python
# Change master to the git tag you want.
Expand Down Expand Up @@ -89,8 +88,10 @@ load("@com_grail_rules_r//R:defs.bzl", "r_package_with_test")
<a name="configuration"></a>
## Configuration

These rules assume that you have R installed on your system (we recommend 3.4.3
or above), and can be located using the `PATH` environment variable.
The following software must be installed on your system:

1. bazel (v3.0.0 or above)
2. R (3.4.3 or above; should be locatable using the `PATH` environment variable)

**NOTE**: After re-installing or upgrading R, please reset the registered
toolchain with `bazel sync --configure` to rebuild your packages with the new
Expand Down
34 changes: 16 additions & 18 deletions tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,12 @@ r_rules_dependencies()

r_register_toolchains()

http_archive(
name = "com_google_protobuf",
sha256 = "d399f651dbdc5f9116a2da199a808c815c0aeeb8d0b46e3213eee5a41263aeff",
strip_prefix = "protobuf-3.8.0-rc1",
urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.8.0-rc1.tar.gz"],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "io_bazel_rules_docker",
sha256 = "4521794f0fba2e20f3bf15846ab5e01d5332e587e9ce81629c7f96c793bb7036",
strip_prefix = "rules_docker-0.14.4",
sha256 = "95d39fd84ff4474babaf190450ee034d958202043e366b9fc38f438c9e6c3334",
strip_prefix = "rules_docker-0.16.0",
urls = [
"https://github.com/bazelbuild/rules_docker/releases/download/v0.14.4/rules_docker-v0.14.4.tar.gz",
"https://github.com/bazelbuild/rules_docker/releases/download/v0.16.0/rules_docker-v0.16.0.tar.gz",
],
)

Expand All @@ -58,10 +47,6 @@ load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load("@io_bazel_rules_docker//repositories:pip_repositories.bzl", "pip_deps")

pip_deps()

load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
Expand Down Expand Up @@ -101,3 +86,16 @@ r_coverage_dependencies()
load("@r_coverage_deps_bzl//:r_repositories.bzl", coverage_deps = "r_repositories")

coverage_deps()

http_archive(
name = "com_google_protobuf",
sha256 = "65e020a42bdab44a66664d34421995829e9e79c60e5adaa08282fd14ca552f57",
strip_prefix = "protobuf-3.15.6",
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v3.15.6.tar.gz",
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
1 change: 1 addition & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ source "./setup-bazel.sh"
# targets. The alternative is to clean the workspace before each test.
set -x
"${bazel}" clean
"${bazel}" version
"${bazel}" run //binary:binary_sh_test
bazel-bin/binary/binary_sh_test
"${bazel}" run //binary:binary_r_test
Expand Down
2 changes: 1 addition & 1 deletion tests/setup-bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ readonly os

# Use bazelisk to catch migration problems.
# Value of BAZELISK_GITHUB_TOKEN is set as a secret on Travis.
readonly url="https://github.com/bazelbuild/bazelisk/releases/download/v1.4.0/bazelisk-${os}-amd64"
readonly url="https://github.com/bazelbuild/bazelisk/releases/download/v1.7.5/bazelisk-${os}-amd64"
bazel="${TMPDIR:-/tmp}/bazelisk"
readonly bazel

Expand Down

0 comments on commit 70cd564

Please sign in to comment.