Skip to content

Commit 321d6f6

Browse files
committed
macOS support
1 parent 87f8993 commit 321d6f6

File tree

14 files changed

+691
-21
lines changed

14 files changed

+691
-21
lines changed

Diff for: BUILD

+208-9
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,37 @@ cc_binary(
545545
deps = ["@zlib_archive//:zlib"],
546546
)
547547

548+
objc_library(
549+
name = "macos_dlg_lib",
550+
srcs = [
551+
CODE_DIR + "/sys/sys_osx.m"
552+
],
553+
hdrs = [
554+
"public/dmlab.h",
555+
CODE_DIR + "/deepmind/context.h",
556+
] + glob(
557+
[
558+
CODE_DIR + "/botlib/*.h",
559+
CODE_DIR + "/client/*.h",
560+
CODE_DIR + "/qcommon/*.h",
561+
CODE_DIR + "/sys/*.h",
562+
CODE_DIR + "/server/*.h",
563+
CODE_DIR + "/renderercommon/*.h",
564+
CODE_DIR + "/renderergl1/*.h",
565+
],
566+
exclude = [
567+
CODE_DIR + "/client/fx_*.h",
568+
CODE_DIR + "/qcommon/vm_powerpc_asm.h",
569+
CODE_DIR + "/qcommon/vm_sparc.h",
570+
CODE_DIR + "/renderercommon/tr_types.h",
571+
CODE_DIR + "/renderercommon/tr_public.h",
572+
CODE_DIR + "/renderergl1/tr_local.h",
573+
],
574+
),
575+
sdk_frameworks = ["Cocoa", "Carbon"],
576+
copts = ["-fno-objc-arc"],
577+
)
578+
548579
# To link with the SDL frontend, depend on :game_lib_sdl
549580
# and add "-lGL" to the linker flags.
550581
cc_library(
@@ -722,7 +753,11 @@ cc_library(
722753
"//third_party/rl_api:env_c_api",
723754
"@jpeg_archive//:jpeg",
724755
"@sdl_system//:sdl2",
725-
],
756+
] + select({
757+
":darwin": ["@osmesa_system//:osmesa"],
758+
":darwin_x86_64": ["@osmesa_system//:osmesa"],
759+
"//conditions:default": [],
760+
}),
726761
)
727762

728763
# To link with the headless GLX frontend, depend on :game_lib_headless_glx
@@ -815,6 +850,94 @@ cc_library(
815850
],
816851
)
817852

853+
cc_library(
854+
name = "game_lib_headless_darwin",
855+
srcs = [
856+
CODE_DIR + "/asm/ftola.c",
857+
CODE_DIR + "/asm/qasm-inline.h",
858+
CODE_DIR + "/asm/snapvector.c",
859+
CODE_DIR + "/cgame/cg_public.h",
860+
CODE_DIR + "/client/libmumblelink.c",
861+
CODE_DIR + "/deepmind/dm_public.h",
862+
CODE_DIR + "/deepmind/dmlab_connect.c",
863+
CODE_DIR + "/game/bg_public.h",
864+
CODE_DIR + "/game/g_public.h",
865+
CODE_DIR + "/null/null_input.c",
866+
CODE_DIR + "/null/null_snddma.c",
867+
CODE_DIR + "/sys/con_log.c",
868+
CODE_DIR + "/sys/con_passive.c",
869+
CODE_DIR + "/sys/sys_main.c",
870+
CODE_DIR + "/sys/sys_unix.c",
871+
CODE_DIR + "/ui/ui_public.h",
872+
873+
## OpenGL rendering
874+
CODE_DIR + "/deepmind/headless_native_macos_glimp.c",
875+
CODE_DIR + "/deepmind/glimp_common.h",
876+
CODE_DIR + "/deepmind/glimp_common.c",
877+
] + glob(
878+
[
879+
CODE_DIR + "/botlib/*.c",
880+
CODE_DIR + "/client/cl_*.c",
881+
CODE_DIR + "/client/snd_*.c",
882+
CODE_DIR + "/qcommon/*.c",
883+
CODE_DIR + "/renderercommon/*.c",
884+
CODE_DIR + "/renderergl1/*.c",
885+
CODE_DIR + "/server/*.c",
886+
],
887+
exclude = [
888+
CODE_DIR + "/renderergl1/tr_subs.c",
889+
CODE_DIR + "/server/sv_rankings.c",
890+
CODE_DIR + "/qcommon/vm_none.c",
891+
CODE_DIR + "/qcommon/vm_powerpc*.c",
892+
CODE_DIR + "/qcommon/vm_sparc.c",
893+
],
894+
),
895+
hdrs = [
896+
"public/dmlab.h",
897+
CODE_DIR + "/deepmind/context.h",
898+
] + glob(
899+
[
900+
CODE_DIR + "/botlib/*.h",
901+
CODE_DIR + "/client/*.h",
902+
CODE_DIR + "/qcommon/*.h",
903+
CODE_DIR + "/sys/*.h",
904+
CODE_DIR + "/server/*.h",
905+
CODE_DIR + "/renderercommon/*.h",
906+
CODE_DIR + "/renderergl1/*.h",
907+
],
908+
exclude = [
909+
CODE_DIR + "/client/fx_*.h",
910+
CODE_DIR + "/qcommon/vm_powerpc_asm.h",
911+
CODE_DIR + "/qcommon/vm_sparc.h",
912+
CODE_DIR + "/renderercommon/tr_types.h",
913+
CODE_DIR + "/renderercommon/tr_public.h",
914+
CODE_DIR + "/renderergl1/tr_local.h",
915+
],
916+
),
917+
copts = [
918+
"-std=c99",
919+
"-fno-strict-aliasing",
920+
ARCH_VAR,
921+
STANDALONE_VAR,
922+
],
923+
defines = [
924+
"BOTLIB",
925+
"_GNU_SOURCE",
926+
],
927+
textual_hdrs = [
928+
CODE_DIR + "/renderercommon/tr_types.h",
929+
CODE_DIR + "/renderercommon/tr_public.h",
930+
CODE_DIR + "/renderergl1/tr_local.h",
931+
],
932+
deps = [
933+
":qcommon_hdrs",
934+
"//deepmind/include:context_headers",
935+
"//third_party/rl_api:env_c_api",
936+
"@jpeg_archive//:jpeg",
937+
"@sdl_system//:sdl2",
938+
],
939+
)
940+
818941
ASSETS = [
819942
"assets/default.cfg",
820943
"assets/q3config.cfg",
@@ -912,61 +1035,124 @@ cc_binary(
9121035
":vm_pk3",
9131036
],
9141037
linkopts = [
915-
"-lGL",
9161038
"-lm",
917-
],
1039+
] + select({
1040+
":darwin": ["-framework OpenGL"],
1041+
":darwin_x86_64": ["-framework OpenGL"],
1042+
"//conditions:default": ["-lGL"],
1043+
}),
9181044
deps = [
9191045
":game_lib_sdl",
9201046
"//deepmind/engine:callbacks",
9211047
"//deepmind/engine:context",
9221048
"@zlib_archive//:zlib",
923-
],
1049+
] + select({
1050+
":darwin": [":macos_dlg_lib"],
1051+
":darwin_x86_64": [":macos_dlg_lib"],
1052+
"//conditions:default": [],
1053+
}),
9241054
)
9251055

9261056
config_setting(
9271057
name = "dmlab_lib_sdl",
9281058
values = {"define": "headless=false"},
9291059
)
9301060

1061+
config_setting(
1062+
name = "dmlab_lib_sdl_darwin",
1063+
values = {"define": "headless=false", "cpu": "darwin"},
1064+
)
1065+
1066+
config_setting(
1067+
name = "dmlab_lib_sdl_darwin_x86_64",
1068+
values = {"define": "headless=false", "cpu": "darwin_x86_64"},
1069+
)
1070+
9311071
config_setting(
9321072
name = "dmlab_headless_hw",
9331073
values = {"define": "headless=glx"},
9341074
)
9351075

1076+
config_setting(
1077+
name = "dmlab_headless_hw_darwin",
1078+
values = {"define": "headless=macos", "cpu": "darwin"},
1079+
)
1080+
1081+
config_setting(
1082+
name = "dmlab_headless_hw_darwin_x86_64",
1083+
values = {"define": "headless=macos", "cpu": "darwin_x86_64"},
1084+
)
1085+
9361086
config_setting(
9371087
name = "dmlab_headless_sw",
9381088
values = {"define": "headless=osmesa"},
9391089
)
9401090

1091+
config_setting(
1092+
name = "dmlab_headless_sw_darwin",
1093+
values = {"define": "headless=osmesa", "cpu": "darwin"},
1094+
)
1095+
1096+
config_setting(
1097+
name = "dmlab_headless_sw_darwin_x86_64",
1098+
values = {"define": "headless=osmesa", "cpu": "darwin_x86_64"},
1099+
)
1100+
9411101
cc_binary(
9421102
name = "libdmlab.so",
9431103
linkopts = select({
9441104
"//conditions:default": ["-lOSMesa"],
1105+
":dmlab_headless_hw_darwin": [
1106+
"-framework OpenGL",
1107+
],
1108+
":dmlab_headless_hw_darwin_x86_64": [
1109+
"-framework OpenGL",
1110+
],
9451111
":dmlab_headless_hw": [
9461112
"-lGL",
9471113
"-lX11",
9481114
],
1115+
":dmlab_lib_sdl_darwin": [
1116+
"-framework OpenGL",
1117+
],
1118+
":dmlab_lib_sdl_darwin_x86_64": [
1119+
"-framework OpenGL",
1120+
],
9491121
":dmlab_lib_sdl": [
9501122
"-lGL",
9511123
"-lX11",
9521124
],
953-
}) + [
954-
"-Wl,--version-script",
955-
":dmlab.lds",
956-
],
1125+
":dmlab_headless_sw_darwin": [],
1126+
":dmlab_headless_sw_darwin_x86_64": [],
1127+
}) + select({
1128+
"//conditions:default": [
1129+
"-Wl,--version-script",
1130+
":dmlab.lds",
1131+
],
1132+
":darwin": [],
1133+
":darwin_x86_64": [],
1134+
}),
9571135
linkshared = 1,
9581136
linkstatic = 1,
9591137
deps = select({
9601138
"//conditions:default": [":game_lib_headless_osmesa"],
9611139
":dmlab_lib_sdl": [":game_lib_sdl"],
9621140
":dmlab_headless_hw": [":game_lib_headless_glx"],
1141+
":dmlab_headless_hw_darwin": [":game_lib_headless_darwin"],
1142+
":dmlab_headless_hw_darwin_x86_64": [":game_lib_headless_darwin"],
9631143
":dmlab_headless_sw": [":game_lib_headless_osmesa"],
1144+
":dmlab_headless_sw_darwin": [":game_lib_headless_osmesa"],
1145+
":dmlab_headless_sw_darwin_x86_64": [":game_lib_headless_osmesa"],
9641146
}) + [
9651147
":dmlab.lds",
9661148
"//deepmind/engine:callbacks",
9671149
"//deepmind/engine:context",
9681150
"@zlib_archive//:zlib",
969-
],
1151+
] + select({
1152+
":darwin": [":macos_dlg_lib"],
1153+
":darwin_x86_64": [":macos_dlg_lib"],
1154+
"//conditions:default": [],
1155+
}),
9701156
)
9711157

9721158
cc_library(
@@ -1007,6 +1193,7 @@ cc_binary(
10071193
deps = [
10081194
":dmlablib",
10091195
"@python_system//:python",
1196+
# "@numpy_archive//:numpy_headers",
10101197
],
10111198
)
10121199

@@ -1038,3 +1225,15 @@ py_test(
10381225
main = "python/random_agent_test.py",
10391226
deps = [":random_agent"],
10401227
)
1228+
1229+
config_setting(
1230+
name = "darwin",
1231+
values = {"cpu": "darwin"},
1232+
visibility = ["//visibility:public"],
1233+
)
1234+
1235+
config_setting(
1236+
name = "darwin_x86_64",
1237+
values = {"cpu": "darwin_x86_64"},
1238+
visibility = ["//visibility:public"],
1239+
)

Diff for: WORKSPACE

+23
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ new_http_archive(
5454
url = "http://bazel-mirror.storage.googleapis.com/zlib.net/zlib-1.2.8.tar.gz",
5555
)
5656

57+
new_http_archive(
58+
name = "numpy_archive",
59+
build_file = "numpy.BUILD",
60+
sha256 = "4c6b4eef790528bebb7ec9590d74cc193868940fe68e4109a91c196df72d8094",
61+
strip_prefix = "numpy-1.13.3",
62+
url = "https://github.com/numpy/numpy/releases/download/v1.13.3/numpy-1.13.3.tar.gz",
63+
)
64+
5765
# TODO: Replace with hermetic build
5866
new_local_repository(
5967
name = "lua_system",
@@ -70,3 +78,18 @@ new_local_repository(
7078
build_file = "python.BUILD",
7179
path = "/usr",
7280
)
81+
new_local_repository(
82+
name = "libxml_system",
83+
build_file = "libxml_system.BUILD",
84+
path = "/usr",
85+
)
86+
new_local_repository(
87+
name = "glib_system",
88+
build_file = "glib_system.BUILD",
89+
path = "/usr",
90+
)
91+
new_local_repository(
92+
name = "osmesa_system",
93+
build_file = "osmesa.BUILD",
94+
path = "/opt",
95+
)

Diff for: deepmind/level_generation/text_level/lua_bindings.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,12 @@ bool LuaCustomEntityCallback(
8686
lua_pop(L, res.n_results());
8787
return false;
8888
} else {
89-
auto is_empty = std::mem_fn(&std::string::empty);
89+
// auto is_empty = std::mem_fn(&std::string::empty);
90+
// NOTE: on macOS clang, the above definition of is_empty causes "ld: 32-bit RIP relative reference out of range" error
91+
// See:
92+
// http://blog.quasardb.net/weird-pie-related-linker-errors-on-os-x/
93+
// http://www.cocoabuilder.com/archive/xcode/317778-os-constant-cause-32-bit-rip-relative-reference-out-of-range-linker-error-on-x64.html#319148
94+
auto is_empty = [](std::string& s){ return s.empty(); };
9095
data.erase(std::remove_if(data.begin(), data.end(), is_empty), data.end());
9196

9297
VLOG(1) << "User callback(" << i << ", " << j << ", '" << ent

0 commit comments

Comments
 (0)