Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[workspace] Factor glx and x11 to share a common implementation #20585

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions tools/workspace/glx/package-macos.BUILD.bazel

This file was deleted.

20 changes: 0 additions & 20 deletions tools/workspace/glx/package-ubuntu.BUILD.bazel

This file was deleted.

50 changes: 12 additions & 38 deletions tools/workspace/glx/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,39 +1,13 @@
load("//tools/workspace:os.bzl", "determine_os")

def _impl(repository_ctx):
os_result = determine_os(repository_ctx)

if os_result.error != None:
fail(os_result.error)

if os_result.is_macos:
# On macOS, no targets should depend on @glx.
build_flavor = "macos"
elif os_result.is_ubuntu or os_result.is_manylinux:
build_flavor = "ubuntu"
hdrs = [
"GL/glx.h",
"GL/glxext.h",
]
for hdr in hdrs:
repository_ctx.symlink(
"/usr/include/{}".format(hdr),
"include/{}".format(hdr),
)
else:
fail("Operating system is NOT supported {}".format(os_result))

repository_ctx.symlink(
Label(
"@drake//tools/workspace/glx:package-{}.BUILD.bazel".format(
build_flavor,
),
),
"BUILD.bazel",
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def glx_repository(name):
pkg_config_repository(
name = name,
licenses = ["notice"], # SGI-B-2.0
modname = "glx",
extra_deps = [
"@opengl",
"@x11",
],
defer_error_os_names = ["mac os x"],
)

glx_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
2 changes: 2 additions & 0 deletions tools/workspace/pkg_config.BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# %{topcomment}

load("@drake//tools/skylark:cc.bzl", "cc_library")

licenses(%{licenses})

package(default_visibility = ["//visibility:public"])
Expand Down
26 changes: 26 additions & 0 deletions tools/workspace/pkg_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ def setup_pkg_config_repository(repository_ctx):
# Check if we can find the required *.pc file of any version.
result = _run_pkg_config(repository_ctx, args, pkg_config_paths)
if result.error != None:
defer_error_os_names = getattr(
repository_ctx.attr,
"defer_error_os_names",
[],
)
if repository_ctx.os.name in defer_error_os_names:
repository_ctx.file(
"BUILD.bazel",
"""
load("@drake//tools/skylark:cc.bzl", "cc_library")
cc_library(
name = {name},
srcs = ["pkg_config_failed.cc"],
visibility = ["//visibility:public"],
)
""".format(
name = repr(repository_ctx.name),
),
)
return struct(value = True, error = None)
return result

# If we have a minimum version, enforce that.
Expand Down Expand Up @@ -326,6 +346,7 @@ _do_pkg_config_repository = repository_rule(
"pkg_config_paths": attr.string_list(),
"homebrew_subdir": attr.string(),
"extra_deprecation": attr.string(),
"defer_error_os_names": attr.string_list(),
},
local = True,
configure = True,
Expand Down Expand Up @@ -389,6 +410,11 @@ def pkg_config_repository(**kwargs):
"/opt/homebrew/opt/libpng/lib/pkgconfig".
extra_deprecation: (Optional) Add a deprecation message to the library
BUILD target.
defer_error_os_names: (Optional) On these operating systems (as named
by repository_ctx.os.name), failure to find the
*.pc file will yield a link-time error, not a
fetch-time error. This is useful for externals
that are guarded by select() statements.
"""
if "deprecation" in kwargs:
fail("When calling pkg_config_repository, don't use deprecation=str " +
Expand Down
11 changes: 0 additions & 11 deletions tools/workspace/x11/package-macos.BUILD.bazel

This file was deleted.

34 changes: 8 additions & 26 deletions tools/workspace/x11/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
load("//tools/workspace:os.bzl", "determine_os")
load("//tools/workspace:pkg_config.bzl", "setup_pkg_config_repository")
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def _impl(repo_ctx):
# Only available on Ubuntu. On macOS, no targets should depend on @x11.
os_result = determine_os(repo_ctx)
if os_result.error != None:
fail(os_result.error)
if os_result.is_ubuntu or os_result.is_manylinux:
error = setup_pkg_config_repository(repo_ctx).error
if error != None:
fail(error)
else:
repo_ctx.symlink(
Label("@drake//tools/workspace/x11:package-macos.BUILD.bazel"),
"BUILD.bazel",
)

x11_repository = repository_rule(
attrs = {
"modname": attr.string(default = "x11"),
"licenses": attr.string_list(default = ["notice"]), # X11/MIT.
},
local = True,
configure = True,
implementation = _impl,
)
def x11_repository(name):
pkg_config_repository(
name = name,
licenses = ["notice"], # X11/MIT
modname = "x11",
defer_error_os_names = ["mac os x"],
)