diff --git a/.github/workflows/macos_bazel.yml b/.github/workflows/macos_bazel.yml index 94f711c5..ee154384 100644 --- a/.github/workflows/macos_bazel.yml +++ b/.github/workflows/macos_bazel.yml @@ -54,3 +54,10 @@ jobs: with: name: macos-pscm-wasm path: bazel-bin/wasm/ + + - name: Build krabby + run: bazel build //project/krabby:krabby -c opt + + - name: Build krabby wasm + run: bazel build //project/krabby:krabby-wasm -c opt + \ No newline at end of file diff --git a/3rd/freetype.BUILD b/3rd/freetype.BUILD new file mode 100644 index 00000000..f7e87c4b --- /dev/null +++ b/3rd/freetype.BUILD @@ -0,0 +1,114 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) + +# We can't just glob *.c, since Freetype has .c files that include other .c +# files all over the place. In order to simplify the process of listing them +# manually, we patch out the non-TrueType drivers from the configuration file, +# since the only font we ship is TrueType. +sources = [ + "src/autofit/afangles.c", + "src/autofit/afblue.c", + "src/autofit/afcjk.c", + "src/autofit/afdummy.c", + "src/autofit/afglobal.c", + "src/autofit/afhints.c", + "src/autofit/afindic.c", + "src/autofit/aflatin.c", + "src/autofit/afloader.c", + "src/autofit/afmodule.c", + "src/autofit/afpic.c", + "src/autofit/afranges.c", + "src/autofit/afshaper.c", + "src/autofit/afwarp.c", + "src/base/basepic.c", + "src/base/ftadvanc.c", + "src/base/ftapi.c", + "src/base/ftbbox.c", + "src/base/ftbdf.c", + "src/base/ftbitmap.c", + "src/base/ftcalc.c", + "src/base/ftcid.c", + "src/base/ftdbgmem.c", + "src/base/ftdebug.c", + "src/base/ftfntfmt.c", + "src/base/ftfstype.c", + "src/base/ftgasp.c", + "src/base/ftgloadr.c", + "src/base/ftglyph.c", + "src/base/ftgxval.c", + "src/base/fthash.c", + "src/base/ftinit.c", + "src/base/ftlcdfil.c", + "src/base/ftmm.c", + "src/base/ftobjs.c", + "src/base/ftotval.c", + "src/base/ftoutln.c", + "src/base/ftpatent.c", + "src/base/ftpfr.c", + "src/base/ftpic.c", + "src/base/ftrfork.c", + "src/base/ftsnames.c", + "src/base/ftstream.c", + "src/base/ftstroke.c", + "src/base/ftsynth.c", + "src/base/ftsystem.c", + "src/base/fttrigon.c", + "src/base/fttype1.c", + "src/base/ftutil.c", + "src/base/ftwinfnt.c", + "src/gzip/ftgzip.c", + "src/raster/ftraster.c", + "src/raster/ftrend1.c", + "src/raster/rastpic.c", + "src/sfnt/pngshim.c", + "src/sfnt/sfdriver.c", + "src/sfnt/sfntpic.c", + "src/sfnt/sfobjs.c", + "src/sfnt/ttbdf.c", + "src/sfnt/ttcmap.c", + "src/sfnt/ttkern.c", + "src/sfnt/ttload.c", + "src/sfnt/ttmtx.c", + "src/sfnt/ttpost.c", + "src/sfnt/ttsbit.c", + "src/smooth/ftgrays.c", + "src/smooth/ftsmooth.c", + "src/smooth/ftspic.c", + "src/truetype/ttdriver.c", + "src/truetype/ttgload.c", + "src/truetype/ttgxvar.c", + "src/truetype/ttinterp.c", + "src/truetype/ttobjs.c", + "src/truetype/ttpic.c", + "src/truetype/ttpload.c", + "src/truetype/ttsubpix.c", +] + +cc_library( + name = "freetype", + srcs = sources, + hdrs = glob([ + "src/**/*.h", + "include/**/*.h", + ]), + copts = [ + "-DFT2_BUILD_LIBRARY", + "-UDEBUG", + ], + includes = ["include"], + textual_hdrs = glob(["src/**/*.c"]), + visibility = ["//visibility:public"], +) diff --git a/3rd/freetype_config.patch b/3rd/freetype_config.patch new file mode 100644 index 00000000..2ebefaab --- /dev/null +++ b/3rd/freetype_config.patch @@ -0,0 +1,26 @@ +diff --git a/include/freetype/config/ftmodule.h b/include/freetype/config/ftmodule.h +index 76d271a..c5950fe 100644 +--- a/include/freetype/config/ftmodule.h ++++ b/include/freetype/config/ftmodule.h +@@ -12,21 +12,10 @@ + + FT_USE_MODULE( FT_Module_Class, autofit_module_class ) + FT_USE_MODULE( FT_Driver_ClassRec, tt_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, t1_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, cff_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, t1cid_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, pfr_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, t42_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, winfnt_driver_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, pcf_driver_class ) +-FT_USE_MODULE( FT_Module_Class, psaux_module_class ) +-FT_USE_MODULE( FT_Module_Class, psnames_module_class ) +-FT_USE_MODULE( FT_Module_Class, pshinter_module_class ) + FT_USE_MODULE( FT_Renderer_Class, ft_raster1_renderer_class ) + FT_USE_MODULE( FT_Module_Class, sfnt_module_class ) + FT_USE_MODULE( FT_Renderer_Class, ft_smooth_renderer_class ) + FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcd_renderer_class ) + FT_USE_MODULE( FT_Renderer_Class, ft_smooth_lcdv_renderer_class ) +-FT_USE_MODULE( FT_Driver_ClassRec, bdf_driver_class ) + + /* EOF */ diff --git a/3rd/sdl2.BUILD b/3rd/sdl2.BUILD new file mode 100644 index 00000000..16ebbded --- /dev/null +++ b/3rd/sdl2.BUILD @@ -0,0 +1,80 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +licenses(["notice"]) + +# Common include paths +sdl_includes = [ + "include", + "src/video/khronos", +] + +objc_library( + name = "sdl2_objc", + srcs = glob([ + "src/**/*.h", + "include/*.h", + ]), + includes = sdl_includes, + non_arc_srcs = glob([ + "src/audio/coreaudio/*.m", + "src/file/cocoa/*.m", + "src/filesystem/cocoa/*.m", + "src/render/metal/*.m", + "src/video/cocoa/*.m", + ]), + sdk_frameworks = [ + "AudioToolbox", + "Carbon", + "CoreAudio", + "CoreVideo", + "Cocoa", + "ForceFeedback", + "IOKit", + "OpenGL", + "Metal", + ], + alwayslink = 1, +) + +sdl_srcs = glob( + include = [ + "src/**/*.c", + "src/**/*.h", + ], + exclude = [ + "src/video/qnx/**", + "src/haptic/windows/**", + "src/test/*.c", + "src/thread/generic/*.c", + "src/core/linux/*.c", + ], +) + +# In general, we bundle SDL2. However, on Linux that would require a header +# generated by --configure, and a lot of buildflags and installing dev headers +# is in general less painful, so we just link it dynamically. +cc_library( + name = "sdl2", + srcs = sdl_srcs, + hdrs = glob(["include/*.h"]), + copts = ["-Wno-error"], + includes = sdl_includes, + textual_hdrs = glob(["src/thread/generic/*.c"]), + visibility = ["//visibility:public"], + deps = select({ + "@platforms//cpu:wasm32": [], + "//conditions:default": [":sdl2_objc"], + }), +) diff --git a/3rd/sdl2_ttf.BUILD b/3rd/sdl2_ttf.BUILD new file mode 100644 index 00000000..e5bd7e29 --- /dev/null +++ b/3rd/sdl2_ttf.BUILD @@ -0,0 +1,26 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cc_library( + name = "sdl2_ttf", + srcs = ["SDL_ttf.c"], + hdrs = ["SDL_ttf.h"], + copts = ["-Wno-error"], + includes = ["."], + visibility = ["//visibility:public"], + deps = [ + "@freetype", + "@sdl2", + ], +) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index dff47814..e9ab8528 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -325,3 +325,30 @@ maybe( "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz", ], ) + +http_archive( + name = "sdl2", + build_file = "@dev_pscm//3rd:sdl2.BUILD", + sha256 = "e6a7c71154c3001e318ba7ed4b98582de72ff970aca05abc9f45f7cbdc9088cb", + strip_prefix = "SDL2-2.0.8", + urls = ["https://www.libsdl.org/release/SDL2-2.0.8.zip"], +) + +http_archive( + name = "sdl2_ttf", + build_file = "@dev_pscm//3rd:sdl2_ttf.BUILD", + sha256 = "ad7a7d2562c19ad2b71fa4ab2e76f9f52b3ee98096c0a7d7efbafc2617073c27", + strip_prefix = "SDL2_ttf-2.0.14", + urls = ["https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.14.zip"], +) + +http_archive( + name = "freetype", + build_file = "@dev_pscm//3rd:freetype.BUILD", + # We patch out some modules we don't use from freetype config file. + patch_args = ["-p1"], + patches = ["@dev_pscm//3rd:freetype_config.patch"], + sha256 = "bf380e4d7c4f3b5b1c1a7b2bf3abb967bda5e9ab480d0df656e0e08c5019c5e6", + strip_prefix = "freetype-2.9", + urls = ["https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz"], +) diff --git a/project/krabby/BUILD.bazel b/project/krabby/BUILD.bazel index e8a407b9..00235221 100644 --- a/project/krabby/BUILD.bazel +++ b/project/krabby/BUILD.bazel @@ -1,19 +1,33 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") # FIXME: -sUSE_SDL=2 -sUSE_SDL_TTF=2 not work with bazel -# cc_binary( -# name = "krabby", -# srcs = ["src/main.cpp"], -# copts = [ -# "-std=c++20", -# ], -# ) -# wasm_cc_binary( -# name = "krabby-wasm", -# cc_target = ":krabby", -# outputs = [ -# "krabby.js", -# "krabby.wasm", -# ], -# ) +filegroup( + name = "asset", + srcs = glob([ + "asset/font/*", + "asset/audio/*", + ]), +) + +cc_binary( + name = "krabby", + srcs = ["src/main.cpp"], + additional_linker_inputs = [":asset"], + copts = [ + "-std=c++20", + ], + data = [":asset"], + # linkopts = ["--preload-file $(locations asset)"], + deps = ["@sdl2_ttf"], +) + +wasm_cc_binary( + name = "krabby-wasm", + cc_target = ":krabby", + outputs = [ + "krabby.js", + "krabby.wasm", + ], + threads = "emscripten", +)