Skip to content

Commit

Permalink
bazel: Allow building with libsdl12's deb-derived system headers and …
Browse files Browse the repository at this point in the history
…libraries, incl. OpenGL.

Also, reformat.
  • Loading branch information
ivucica committed Mar 25, 2024
1 parent 12d6fa1 commit fd9bd88
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 23 deletions.
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*-Python-*-
workspace(name="glict")
workspace(name = "glict")

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "rules_libsdl12",
commit = "ff61b0a18827602cbc72b8bd823bdc70a59975d7",
commit = "14dd7d24caa2d8d3b1ef77186a187702c8df1c12",
remote = "https://github.com/ivucica/rules_libsdl12",
)

Expand Down
5 changes: 5 additions & 0 deletions glict/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ cc_binary(
"//glict/GLICT",
] + select({
":darwin": ["@libsdl12//:sdlmain"],
"//glict/GLICT:linux_deps_bin": ["@libgl1//:libgl1", "@libgl-dev//:libgl-dev"], # TODO: remove if possible, linking with :sdl should do this
"//conditions:default": [],
}),
copts = select({
"//conditions:default": [],
"//glict/GLICT:linux_deps_bin": ["-isystem", "external/libgl-dev/usr/include"], # TODO: remove if possible, linking with :sdl should do this
}),
data = [
"@libsdl12//:sdlheaders",
],
Expand Down
68 changes: 59 additions & 9 deletions glict/GLICT/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ config_setting(
visibility = ["//:__subpackages__"],
)


# With --define libsdl12_linux_deps_bin=true, a prebuilt set of x64 binary
# packages for dependencies will be used. Useful for remote builds where local
# headers and libs will not be installed.
#
# Ideally libsdl12 itself would offer us a way to link against the correct
# libraries such as libGL without having to pass this.
config_setting(
name = "linux_deps_bin",
values = {"define": "libsdl12_linux_deps_bin=true"},
)

cc_library(
name = "GLICT",
srcs = [
Expand Down Expand Up @@ -56,23 +68,61 @@ cc_library(
"types.h",
"window.h",
],
includes = ["."],
visibility = ["//visibility:public"],

copts = select({
# rules_libsdl12 needs system OpenGL headers.
# Passed as copts since we know their path, but passing these -isystem paths in includes is not feasible as those paths are Bazel-package-relative.
# (Hence they should be specified by libgl-dev instead, which is something that can be tackled in the future.)
":windows": [],
":windows_msys": [],
":windows_msvc": [],
":darwin": [],
"//conditions:default": [],
":linux_deps_bin": [
# Only use when rules_libsdl12 uses debs. Ideally we'd just pass on something where rules_libsdl12 would make the call. Not there yet.
"-isystem",
"external/libgl-dev/usr/include/",
],
}),
defines = select({
":windows": ["WIN32"],
":windows_msys": ["WIN32"],
":windows_msvc": ["WIN32"],
":windows_msys": ["WIN32"],
":windows_msvc": ["WIN32"],
"//conditions:default": [],
}),
includes = ["."],
linkopts = select({
":windows": ["-lopengl32",],
":windows_msys": ["-lopengl32",],
":windows_msvc": ["-lopengl32",],
":windows": ["-lopengl32"],
":windows_msys": ["-lopengl32"],
":windows_msvc": ["-lopengl32"],
":darwin": ["-framework OpenGL"],
"//conditions:default": ["-lGL"],
":linux_deps_bin": [
#"-lGL", <-- it's libGL.so.1.7.0 inside libgl1, and we don't have a symlink to help find it
# Ideally dep on libgl-dev should fix the search path, and maybe the
# linking with libGL as well.
"-Lexternal/libgl-dev/usr/lib/x86_64-linux-gnu/",
"-Lexternal/libgl1/usr/lib/x86_64-linux-gnu/",
],
}),
visibility = ["//visibility:public"],
deps = [
":glict_sys_headers",
] + select({
":windows": [],
":windows_msys": [],
":windows_msvc": [],
":darwin": [],
"//conditions:default": [],
":linux_deps_bin": [
# rules_libsdl12 can provide "system" OpenGL headers.

# TODO: only use when rules_libsdl12 uses debs, without depending on the :linux_deps_bin.
"@libgl-dev//:libgl-dev", # Pull in GL/gl.h.
"@libgl-dev//:hdrs", # Pull in GL/gl.h.
"@libgl1//:libs", # Pull in libGL.so.1.7.0 as libGL.so symlinks to it and we have no other way to refer to it.
"@x11repository//:X11",
],
}),
deps = ["glict_sys_headers"],
)

# make #include <GLICT/foo.h> work
Expand Down
45 changes: 33 additions & 12 deletions glict/examples/memory_sdl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,50 @@ cc_binary(
"sdlfont.cpp",
"sdlfont.h",
],
deps = [
"@libsdl12//:sdl",
"@libsdl12//:sdlmain",
"//glict/GLICT",
],
data = [
"@libsdl12//:sdlheaders",
"font.bmp",
],
copts = select({
"//glict/GLICT:windows": ["-DBAZEL_WIN32"],
"//glict/GLICT:windows_msys": [],
"//glict/GLICT:windows_msvc": ["-DBAZEL_WIN32"],
"//conditions:default": []
"//glict/GLICT:windows_msvc": ["-DBAZEL_WIN32"],
"//conditions:default": [],
"//glict/GLICT:linux_deps_bin": [
"-isystem", "external/libgl-dev/usr/include/",
],
}),
data = [
"font.bmp",
"@libsdl12//:sdlheaders",
],
linkopts = select({
"//glict/GLICT:windows": ["-SUBSYSTEM:CONSOLE"],
"//glict/GLICT:windows_msys": [],
"//glict/GLICT:windows_msvc": ["-SUBSYSTEM:CONSOLE"],
"//glict/GLICT:windows_msvc": ["-SUBSYSTEM:CONSOLE"],
"//conditions:default": [
"-ldl",
"-pthread",
],
"//glict/GLICT:linux_deps_bin": [
"-ldl",
"-pthread",
# Ideally dep on libgl-dev should fix the search path, and maybe the
# linking with libGL as well.
# This should also be added only if rules_libsdl12 decided to use
# .deb-derived binaries and headers.
"-Lexternal/libgl-dev/usr/lib/x86_64-linux-gnu/",
],
}),
deps = [
"//glict/GLICT",
"@libsdl12//:sdl",
"@libsdl12//:sdlmain",
] + select({
"//conditions:default": [],
"//glict/GLICT:linux_deps_bin": [
"@libgl-dev//:hdrs",
#"@libgl-dev//:libgl-dev",
#"@libgl-dev//:libs",
#"@libgl1//:libs",
#"@libgl1//:libGL",
],
}),
)

Expand Down

0 comments on commit fd9bd88

Please sign in to comment.