diff --git a/.github/workflows/precommit.yml b/.github/workflows/precommit.yml index 859dcd34c..4c4818a39 100644 --- a/.github/workflows/precommit.yml +++ b/.github/workflows/precommit.yml @@ -13,18 +13,17 @@ on: jobs: build-and-test: - name: Build and test ${{matrix.cfg.name}} ${{matrix.os.name}} + name: Build and test ${{matrix.cfg.name}} - runs-on: ${{matrix.os.id}} + runs-on: ${{matrix.cfg.os}} strategy: matrix: - os: - - { name: 'Linux', id: 'ubuntu-20.04' } cfg: - - { name: 'GCC', cc: gcc-10, cxx: g++-10, config: --copt=-Wno-maybe-uninitialized } - - { name: 'LLVM+libstdc++', cc: clang, cxx: clang++, config: --copt=-Wno-uninitialized } - - { name: 'LLVM+libc++', cc: clang, cxx: clang++, config: --config=libc++ --copt=-Wno-uninitialized } + - { name: 'Linux GCC', os: 'ubuntu-20.04', cc: gcc-10, cxx: g++-10, config: --copt=-Wno-maybe-uninitialized } + - { name: 'Linux LLVM+libstdc++', os: 'ubuntu-20.04', cc: clang, cxx: clang++, config: --copt=-Wno-uninitialized } + - { name: 'Linux LLVM+libc++', os: 'ubuntu-20.04', cc: clang, cxx: clang++, config: --config=libc++ --copt=-Wno-uninitialized } + - { name: 'MacOS LLVM+libc++', os: 'macos-10.15', config: --config=libc++ --copt=-Wno-uninitialized } env: CC: ${{matrix.cfg.cc}} @@ -32,16 +31,26 @@ jobs: steps: - uses: actions/checkout@v2 - - name: install infrastructure + - name: install infrastructure (Linux) + if: matrix.cfg.os == 'ubuntu-20.04' run: | sudo apt-get update sudo apt-get install gettext python2-dev python3-dev libsdl2-dev libosmesa6-dev python-numpy-dev python3-numpy-dev python-pil python3-pil python-enum34 sudo find /usr -type f -name Python.h -o -name arrayobject.h -o -name functional -o -name -filesystem sudo ln -s /usr/lib/llvm-10/include/c++/v1 /usr/include/c++/v1 - - name: build + - name: install infrastructure (MacOS) + if: matrix.cfg.os == 'macos-10.15' + run: | + brew install SDL2 + sudo -H pip install numpy + sudo -H pip3 install numpy + sudo find -L /usr /Library -type f -name SDL.h -o -name glib.h -o -name Python.h -o -name arrayobject.h + - name: build (Linux) + if: matrix.cfg.os == 'ubuntu-20.04' run: | bazel --bazelrc=.precommit.bazelrc build ${{matrix.cfg.config}} --copt=-Wno-sign-compare //... - - name: run-tests + - name: run-tests (Linux) + if: matrix.cfg.os == 'ubuntu-20.04' timeout-minutes: 45 run: | bazel --bazelrc=.precommit.bazelrc test ${{matrix.cfg.config}} --copt=-Wno-sign-compare //... @@ -49,6 +58,12 @@ jobs: bazel --bazelrc=.precommit.bazelrc test ${{matrix.cfg.config}} --copt=-Wno-sign-compare //python/tests:python_module_test.py3 --test_tag_filters="" --test_arg=--verbose bazel --bazelrc=.precommit.bazelrc test ${{matrix.cfg.config}} --copt=-Wno-sign-compare //python/tests:dmenv_module_test.py2 --test_tag_filters="" --test_arg=--verbose bazel --bazelrc=.precommit.bazelrc test ${{matrix.cfg.config}} --copt=-Wno-sign-compare //python/tests:dmenv_module_test.py3 --test_tag_filters="" --test_arg=--verbose - - name: run-agent + - name: run-agent (Linux) + if: matrix.cfg.os == 'ubuntu-20.04' run: | bazel --bazelrc=.precommit.bazelrc run ${{matrix.cfg.config}} --copt=-Wno-sign-compare --define headless=osmesa //:python_random_agent + - name: build-and-run-tests (MacOS) + if: matrix.cfg.os == 'macos-10.15' + timeout-minutes: 45 + run: | + bazel --bazelrc=.precommit.bazelrc build ${{matrix.cfg.config}} --copt=-Wno-sign-compare -c opt --dynamic_mode=off --show_progress_rate_limit=10 //:game_lib_headless_macos diff --git a/BUILD b/BUILD index 195c6572d..75f602249 100644 --- a/BUILD +++ b/BUILD @@ -827,6 +827,27 @@ cc_library( alwayslink = 1, ) +cc_library( + name = "game_lib_headless_macos", + srcs = IOQ3_COMMON_SRCS + [ + CODE_DIR + "/deepmind/dmlab_connect.c", + CODE_DIR + "/null/null_input.c", + CODE_DIR + "/null/null_snddma.c", + + ## OpenGL rendering + CODE_DIR + "/deepmind/headless_macos_glimp.c", + CODE_DIR + "/deepmind/glimp_common.h", + CODE_DIR + "/deepmind/glimp_common.c", + ], + hdrs = ["public/dmlab.h"], + copts = IOQ3_COMMON_COPTS, + defines = IOQ3_COMMON_DEFINES, + linkopts = ["-framework OpenGL"], + tags = ["manual"], # don't build on Linux with //... + deps = IOQ3_COMMON_DEPS, + alwayslink = 1, +) + cc_library( name = "game_lib_headless_osmesa", srcs = IOQ3_COMMON_SRCS + [ @@ -929,11 +950,13 @@ config_setting( config_setting( name = "dmlab_graphics_osmesa_or_glx", + constraint_values = ["@platforms//os:linux"], define_values = {"graphics": "osmesa_or_glx"}, ) config_setting( name = "dmlab_graphics_osmesa_or_egl", + constraint_values = ["@platforms//os:linux"], define_values = {"graphics": "osmesa_or_egl"}, ) @@ -947,6 +970,7 @@ cc_binary( linkstatic = 1, visibility = ["//testing:__subpackages__"], deps = [":dmlab.lds"] + select({ + "is_macos": [":game_lib_headless_macos"], "dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"], "dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"], "//conditions:default": [":game_lib_headless_egl"], diff --git a/engine/code/deepmind/headless_macos_glimp.c b/engine/code/deepmind/headless_macos_glimp.c new file mode 100644 index 000000000..659b704eb --- /dev/null +++ b/engine/code/deepmind/headless_macos_glimp.c @@ -0,0 +1,58 @@ +#include +#include +#include + +#include +#include + +#include "glimp_common.h" + +static CGLContextObj context; + +void GLimp_MakeCurrent(void) { +} + +void GLimp_Init(void) { + CGLPixelFormatObj pix; + GLint npix; + int attribs[] = { + kCGLPFAAccelerated, // no software rendering + kCGLPFAOpenGLProfile, + kCGLOGLPVersion_Legacy, + 0 + }; + + GLimp_CommonPreInit(); + + // NOTE: in headless mode there is no GUI, hence output to console instead of message boxes + + if (CGLChoosePixelFormat((CGLPixelFormatAttribute*)attribs, &pix, &npix) != kCGLNoError) { + // Sys_Error("GLimp_Init - choose pixel format error!\n"); + printf("GLimp_Init - choose pixel format error!\n"); + exit(1); + } + if (CGLCreateContext(pix, NULL, &context) != kCGLNoError) { + // Sys_Error("GLimp_Init - create context error!\n"); + printf("GLimp_Init - create context error!\n"); + exit(1); + } + if (CGLSetCurrentContext(context) != kCGLNoError) { + // Sys_Error("GLimp_Init - set current context error!"); + printf("GLimp_Init - set current context error!\n"); + exit(1); + } + CGLDestroyPixelFormat(pix); + + printf("Renderer: %s\nVersion: %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION)); + + GLimp_CommonPostInit(); +} + +void* GLimp_GetProcAddress(const char* func) { + return dlsym(RTLD_SELF, func); +} + +void GLimp_Shutdown(void) { + CGLSetCurrentContext(NULL); + CGLDestroyContext(context); +}