Skip to content

Commit

Permalink
Do not use pkg-config to find libjpeg and yaml-cpp (#13335)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiesnape authored May 19, 2020
1 parent c80fb53 commit 29e09b2
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 40 deletions.
15 changes: 15 additions & 0 deletions tools/workspace/libjpeg/package-macos.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- python -*-

licenses(["notice"]) # IJG

cc_library(
name = "libjpeg",
hdrs = glob(["include/*.h"]),
includes = ["include"],
linkopts = [
"-L/usr/local/opt/jpeg/lib",
"-Wl,-rpath,/usr/local/opt/jpeg/lib",
"-ljpeg",
],
visibility = ["//visibility:public"],
)
14 changes: 14 additions & 0 deletions tools/workspace/libjpeg/package-ubuntu.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- python -*-

licenses(["notice"]) # IJG

cc_library(
name = "libjpeg",
hdrs = glob(["include/*.h"]),
includes = ["include"],
linkopts = [
"-L/usr/lib/x86_64-linux-gnu",
"-ljpeg",
],
visibility = ["//visibility:public"],
)
56 changes: 38 additions & 18 deletions tools/workspace/libjpeg/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
# -*- mode: python -*-
# -*- python -*-

load(
"@drake//tools/workspace:pkg_config.bzl",
"pkg_config_repository",
)
load("@drake//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)

def libjpeg_repository(
name,
licenses = ["notice"], # IJG
modname = "libjpeg",
pkg_config_paths = ["/usr/local/opt/libjpeg/lib/pkgconfig"],
**kwargs):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
**kwargs
)
if os_result.is_macos:
repository_ctx.symlink("/usr/local/opt/jpeg/include", "include")
repository_ctx.symlink(
Label("@drake//tools/workspace/libjpeg:package-macos.BUILD.bazel"),
"BUILD.bazel",
)
elif os_result.is_ubuntu:
for hdr in ["jerror.h", "jmorecfg.h", "jpegint.h", "jpeglib.h"]:
repository_ctx.symlink(
"/usr/include/{}".format(hdr),
"include/{}".format(hdr),
)
repository_ctx.symlink(
"/usr/include/x86_64-linux-gnu/jconfig.h",
"include/jconfig.h",
)
repository_ctx.symlink(
Label(
"@drake//tools/workspace/libjpeg:package-ubuntu.BUILD.bazel",
),
"BUILD.bazel",
)
else:
fail("Operating system is NOT supported", attr = os_result)

libjpeg_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)
15 changes: 15 additions & 0 deletions tools/workspace/yaml_cpp/package-macos.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- python -*-

licenses(["notice"]) # X11

cc_library(
name = "yaml_cpp",
hdrs = glob(["include/yaml-cpp/*.h"]),
includes = ["include"],
linkopts = [
"-L/usr/local/opt/yaml-cpp/lib",
"-Wl,-rpath,/usr/local/opt/yaml-cpp/lib",
"-lyaml-cpp",
],
visibility = ["//visibility:public"],
)
15 changes: 15 additions & 0 deletions tools/workspace/yaml_cpp/package-ubuntu-18.04.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- python -*-

licenses(["notice"]) # X11

cc_library(
name = "yaml_cpp",
hdrs = glob(["include/yaml-cpp/*.h"]),
includes = ["include"],
linkopts = [
"-L/usr/lib/x86_64-linux-gnu",
"-lyaml-cpp",
],
visibility = ["//visibility:public"],
deps = ["@boost//:boost_headers"],
)
14 changes: 14 additions & 0 deletions tools/workspace/yaml_cpp/package-ubuntu-20.04.BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- python -*-

licenses(["notice"]) # X11

cc_library(
name = "yaml_cpp",
hdrs = glob(["include/yaml-cpp/*.h"]),
includes = ["include"],
linkopts = [
"-L/usr/lib/x86_64-linux-gnu",
"-lyaml-cpp",
],
visibility = ["//visibility:public"],
)
60 changes: 38 additions & 22 deletions tools/workspace/yaml_cpp/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
# -*- mode: python -*-
# -*- python -*-

load(
"@drake//tools/workspace:pkg_config.bzl",
"pkg_config_repository",
)
load("@drake//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)

def yaml_cpp_repository(
name,
licenses = ["notice"], # X11
modname = "yaml-cpp",
atleast_version = "0.5.2",
extra_deps = ["@boost//:boost_headers"],
pkg_config_paths = ["/usr/local/opt/yaml-cpp/lib/pkgconfig"],
**kwargs):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
atleast_version = atleast_version,
extra_deps = extra_deps,
pkg_config_paths = pkg_config_paths,
**kwargs
)
if os_result.is_macos:
repository_ctx.symlink(
"/usr/local/opt/yaml-cpp/include/yaml-cpp",
"include/yaml-cpp",
)
repository_ctx.symlink(
Label(
"@drake//tools/workspace/yaml_cpp:package-macos.BUILD.bazel",
),
"BUILD.bazel",
)
elif os_result.is_ubuntu:
repository_ctx.symlink("/usr/include/yaml-cpp", "include/yaml-cpp")
repository_ctx.symlink(
Label(
("@drake//tools/workspace/yaml_cpp" +
":package-ubuntu-{}.BUILD.bazel").format(
os_result.ubuntu_release,
),
),
"BUILD.bazel",
)
else:
fail("Operating system is NOT supported", attr = os_result)

yaml_cpp_repository = repository_rule(
local = True,
configure = True,
implementation = _impl,
)

0 comments on commit 29e09b2

Please sign in to comment.