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

Get SDL2, ImGui, and graphics sample building on Windows with Bazel. #180

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 2 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ build:x86opt --copt=-mavx2
build:windows --copt=-Wno-builtin-macro-redefined --host_copt=-Wno-builtin-macro-redefined
build:windows --copt=-Wno-unknown-argument --host_copt=-Wno-unknown-argument

# Disables windows headers from pulling in GDI, which does a lot of terrible
# things (such as defining the ERROR macro, which breaks the world).
build:windows --copt=-DNOGDI --host_copt=-DNOGDI
# Avoid warnings for WIN32_LEAN_AND_MEAN being defined multiple times.
build:windows --copt=-Wno-macro-redefined

# Enables unix-style runfiles link trees (requires symlink permission).
# See: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/
Expand Down
12 changes: 12 additions & 0 deletions build_tools/third_party/dear_imgui/BUILD.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ cc_library(
"@sdl2//:SDL2",
],
)

cc_binary(
name = "example_sdl_vulkan",
srcs = [
"examples/example_sdl_vulkan/main.cpp",
],
deps = [
":dear_imgui_srcs",
":imgui_sdl_vulkan_srcs",
],
includes = ["examples/"],
)
31 changes: 19 additions & 12 deletions build_tools/third_party/sdl2/BUILD.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ sdl_sources = select({
"src/**/*.h",
],
exclude = [
# Ignore test files
"src/test/*.c",
"src/video/qnx/**",
# Ignore Linux/Unix
"src/core/linux/**",
"src/thread/**",
"src/core/unix/**",
# Ignore thread (exclude for thread/windows)
"src/thread/**",
# Remove support for QNX
"src/video/qnx/**",
],
) + glob([
"src/thread/*",
Expand Down Expand Up @@ -117,6 +121,7 @@ sdl_headers = [
]

sdl_copts = select({
"@bazel_tools//src/conditions:windows": [],
"//conditions:default": [
"-Wno-string-conversion",
"-pthread",
Expand All @@ -126,16 +131,18 @@ sdl_copts = select({

sdl_linkopts = select({
"@bazel_tools//src/conditions:windows": [
"-Wl,advapi32.lib",
"-Wl,gdi32.lib",
"-Wl,imm32.lib",
"-Wl,ole32.lib",
"-Wl,oleaut32.lib",
"-Wl,opengl32.lib",
"-Wl,shell32.lib",
"-Wl,user32.lib",
"-Wl,version.lib",
"-Wl,winmm.lib",
"-DEFAULTLIB:user32",
"-DEFAULTLIB:gdi32",
"-DEFAULTLIB:winmm",
"-DEFAULTLIB:imm32",
"-DEFAULTLIB:ole32",
"-DEFAULTLIB:oleaut32",
"-DEFAULTLIB:version",
"-DEFAULTLIB:uuid",
"-DEFAULTLIB:shell32",
"-DEFAULTLIB:advapi32",
"-DEFAULTLIB:hid",
"-DEFAULTLIB:setupapi",
],
"//conditions:default": [
"-ldl",
Expand Down
7 changes: 4 additions & 3 deletions build_tools/third_party/sdl2/SDL_config_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef _SDL_config_linux_h
#define _SDL_config_linux_h
#ifndef SDL_config_linux_h
#define SDL_config_linux_h
#define SDL_config_h_

/**
* \file SDL_config_linux.h
Expand Down Expand Up @@ -401,4 +402,4 @@
/* Enable dynamic libsamplerate support */
/* #undef SDL_LIBSAMPLERATE_DYNAMIC */

#endif /* _SDL_config_linux_h */
#endif /* SDL_config_linux_h */
25 changes: 16 additions & 9 deletions build_tools/third_party/sdl2/SDL_config_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

#include "SDL_platform.h"

// Explicitly include headers for SSE intrinsics.
// SDL itself conditionally chooses to not include these on Windows, but they
// appear to be needed on some systems anyway.
#include <intrin.h>
#include <xmmintrin.h>

/* This is a set of defines to configure the SDL features */

#if !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
Expand Down Expand Up @@ -64,6 +70,7 @@ typedef unsigned int uintptr_t;

/* This is disabled by default to avoid C runtime dependencies and manifest
* requirements */
#define HAVE_LIBC 1 // Enable it anyway :D
#ifdef HAVE_LIBC
/* Useful headers */
#define STDC_HEADERS 1
Expand Down Expand Up @@ -180,35 +187,35 @@ typedef unsigned int uintptr_t;
/* Enable various timer systems */
#define SDL_TIMER_WINDOWS 1

/* Enable various video drivers */
/* Enable/disable various video drivers */
#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_WINDOWS 1

#ifndef SDL_VIDEO_RENDER_D3D
#define SDL_VIDEO_RENDER_D3D 1
#define SDL_VIDEO_RENDER_D3D 0
#endif
#ifndef SDL_VIDEO_RENDER_D3D11
#define SDL_VIDEO_RENDER_D3D11 0
#endif

/* Enable OpenGL support */
/* Disable OpenGL support, just use Vulkan */
#ifndef SDL_VIDEO_OPENGL
#define SDL_VIDEO_OPENGL 1
#define SDL_VIDEO_OPENGL 0
#endif
#ifndef SDL_VIDEO_OPENGL_WGL
#define SDL_VIDEO_OPENGL_WGL 1
#define SDL_VIDEO_OPENGL_WGL 0
#endif
#ifndef SDL_VIDEO_RENDER_OGL
#define SDL_VIDEO_RENDER_OGL 1
#define SDL_VIDEO_RENDER_OGL 0
#endif
#ifndef SDL_VIDEO_RENDER_OGL_ES2
#define SDL_VIDEO_RENDER_OGL_ES2 1
#define SDL_VIDEO_RENDER_OGL_ES2 0
#endif
#ifndef SDL_VIDEO_OPENGL_ES2
#define SDL_VIDEO_OPENGL_ES2 1
#define SDL_VIDEO_OPENGL_ES2 0
#endif
#ifndef SDL_VIDEO_OPENGL_EGL
#define SDL_VIDEO_OPENGL_EGL 1
#define SDL_VIDEO_OPENGL_EGL 0
#endif

/* Enable Vulkan support */
Expand Down
2 changes: 1 addition & 1 deletion build_tools/third_party/vulkan_sdk/repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ cc_library(
name = "sdk",
srcs = select({
"@bazel_tools//src/conditions:windows": [
"Lib/vulkan-1.lib"
"vulkan-sdk/Lib/vulkan-1.lib"
],
"//conditions:default": [
"vulkan-sdk/lib/libvulkan.so.1",
Expand Down