diff --git a/.bazelrc b/.bazelrc index 7714123..c661c17 100644 --- a/.bazelrc +++ b/.bazelrc @@ -9,3 +9,7 @@ sync --experimental_repository_resolved_file=resolved.bzl build --experimental_resolved_file_instead_of_workspace=resolved.bzl build --experimental_repository_hash_file=resolved.bzl build --experimental_verify_repository_rules=@bazel_tools//tools/build_defs/repo:git.bzl%git_repository + +# much sandbox +build --spawn_strategy=worker,sandboxed +build --worker_sandboxing diff --git a/WORKSPACE b/WORKSPACE index 98a4651..d20d4c0 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -77,3 +77,27 @@ upgradable_repository( build_file = "@//third_party:getopt.BUILD", remote = "git://github.com/skandhurkat/Getopt-for-Visual-Studio.git", ) + +# From https://github.com/fmtlib/fmt/blob/1b193e7b3716f57d64fa2f98275eb1395fea4eff/support/bazel/README.md + +upgradable_repository( + name = "fmt", + patch_cmds = [ + "mv support/bazel/.bazelrc .bazelrc", + "mv support/bazel/.bazelversion .bazelversion", + "mv support/bazel/BUILD.bazel BUILD.bazel", + "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel", + ], + # Windows-related patch commands are only needed in the case MSYS2 is not installed. + # More details about the installation process of MSYS2 on Windows systems can be found here: + # https://docs.bazel.build/versions/main/install-windows.html#installing-compilers-and-language-runtimes + # Even if MSYS2 is installed the Windows related patch commands can still be used. + patch_cmds_win = [ + "Move-Item -Path support/bazel/.bazelrc -Destination .bazelrc", + "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion", + "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel", + "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel", + ], + remote = "git://github.com/fmtlib/fmt.git", + tag = "~8", +) diff --git a/resolved.bzl b/resolved.bzl index 8543e9a..b282bbe 100644 --- a/resolved.bzl +++ b/resolved.bzl @@ -121,6 +121,67 @@ resolved = [ }, ], }, + { + "original_rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", + "original_attributes": { + "name": "fmt", + "patch_cmds": [ + "mv support/bazel/.bazelrc .bazelrc", + "mv support/bazel/.bazelversion .bazelversion", + "mv support/bazel/BUILD.bazel BUILD.bazel", + "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel", + ], + "patch_cmds_win": [ + "Move-Item -Path support/bazel/.bazelrc -Destination .bazelrc", + "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion", + "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel", + "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel", + ], + "remote": "git://github.com/fmtlib/fmt.git", + "tag": "~8", + }, + "repositories": [ + { + "rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", + "attributes": { + "urls": [ + "https://github.com/fmtlib/fmt/archive/64dc8fbada9898fccddce0dda3cb0c9695712a3d.tar.gz", + ], + "sha256": "a4acec95f266e7a69d1f3038bc4dd06da042ab0e36900a83484f8f144b27080d", + "netrc": "", + "auth_patterns": {}, + "canonical_id": "", + "strip_prefix": "fmt-64dc8fbada9898fccddce0dda3cb0c9695712a3d", + "type": "tar.gz", + "patches": [], + "patch_tool": "", + "patch_args": [ + "-p0", + ], + "patch_cmds": [ + "mv support/bazel/.bazelrc .bazelrc", + "mv support/bazel/.bazelversion .bazelversion", + "mv support/bazel/BUILD.bazel BUILD.bazel", + "mv support/bazel/WORKSPACE.bazel WORKSPACE.bazel", + ], + "patch_cmds_win": [ + "Move-Item -Path support/bazel/.bazelrc -Destination .bazelrc", + "Move-Item -Path support/bazel/.bazelversion -Destination .bazelversion", + "Move-Item -Path support/bazel/BUILD.bazel -Destination BUILD.bazel", + "Move-Item -Path support/bazel/WORKSPACE.bazel -Destination WORKSPACE.bazel", + ], + "build_file_content": "", + "workspace_file_content": "", + "branch": "", + "release": "", + "remote": "git://github.com/fmtlib/fmt.git", + "tag": "~8", + "name": "fmt", + }, + "output_tree_hash": "c1803a5e21a85414df77d03400f7a818d41086496f9ee03af65d4fb042ee656a", + }, + ], + }, { "original_rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", "original_attributes": { @@ -261,13 +322,13 @@ resolved = [ "rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", "attributes": { "urls": [ - "https://github.com/glfw/glfw/archive/81d762bf66de89343eea400bd37efda161272535.tar.gz", + "https://github.com/glfw/glfw/archive/869e68a01579e87a4823e6e88893ac274422eec4.tar.gz", ], - "sha256": "e78464328273d810ded3c1dd8b6cec4840080e554d07934f7ecec71ed278889f", + "sha256": "6468b458c163bb39e1f3b16b7726c3ac14716fe46cb71be61b7ba97402eec757", "netrc": "", "auth_patterns": {}, "canonical_id": "", - "strip_prefix": "glfw-81d762bf66de89343eea400bd37efda161272535", + "strip_prefix": "glfw-869e68a01579e87a4823e6e88893ac274422eec4", "type": "tar.gz", "patches": [], "patch_tool": "", @@ -285,7 +346,7 @@ resolved = [ "tag": "", "name": "glfw", }, - "output_tree_hash": "4b56c95d240132034ba6f6016e8763b9aabd101aabf9ea500f8a432da64ceb8e", + "output_tree_hash": "88ebe8b7b6a3c0003e4c079267eeeaa1b345ce5b475396952d576275b824e9f6", }, ], }, @@ -304,13 +365,13 @@ resolved = [ "rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", "attributes": { "urls": [ - "https://github.com/glfw/glfw/releases/download/3.3.5/glfw-3.3.5.bin.MACOS.zip", + "https://github.com/glfw/glfw/releases/download/3.3.6/glfw-3.3.6.bin.MACOS.zip", ], - "sha256": "184f165464ed9c46effd96c9fb6e355996d62f5f96f5e90542f00775fe781511", + "sha256": "288b572bbb8da3e0a48acf98354a91eb225adc03354dfa7212ee610852e4756d", "netrc": "", "auth_patterns": {}, "canonical_id": "", - "strip_prefix": "glfw-3.3.5.bin.MACOS", + "strip_prefix": "glfw-3.3.6.bin.MACOS", "type": "zip", "patches": [], "patch_tool": "", @@ -328,7 +389,7 @@ resolved = [ "tag": "~3", "name": "glfw_osx", }, - "output_tree_hash": "8bfd001632546166c2d147f2921c40a105029eef8d05166ddce756a01174e125", + "output_tree_hash": "92f15c4c1dee77f2824d3b190160e405da7bd466e07864e58ee07800da1fde01", }, ], }, @@ -385,13 +446,13 @@ resolved = [ "rule_class": "@bazel_upgradable//:rule.bzl%upgradable_repository", "attributes": { "urls": [ - "https://github.com/KhronosGroup/OpenGL-Registry/archive/a48c224a2db6edc4f4c610025b529d1c31ee9445.tar.gz", + "https://github.com/KhronosGroup/OpenGL-Registry/archive/84e297a87b9c3a660d11667ed7cec557906c1933.tar.gz", ], - "sha256": "7b89003871bfd4a9ba06dc5c28c163726f6f019a66386654e5d29a6d8ee18f93", + "sha256": "5e7680152faf2dde14b3c1b436765681c45731432f9089215c30498abaedf621", "netrc": "", "auth_patterns": {}, "canonical_id": "", - "strip_prefix": "OpenGL-Registry-a48c224a2db6edc4f4c610025b529d1c31ee9445", + "strip_prefix": "OpenGL-Registry-84e297a87b9c3a660d11667ed7cec557906c1933", "type": "tar.gz", "patches": [], "patch_tool": "", @@ -409,7 +470,7 @@ resolved = [ "tag": "", "name": "khronos_opengl_registry", }, - "output_tree_hash": "bf605749708e8158d41aa39c943da121e5028b653edb2583fb0c5d41397f3c6a", + "output_tree_hash": "b9d1b80b21b961ef1c7f83dd3ddb13ce72f521a39a51c96751e1b8c6a932750a", }, ], }, diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 3709d24..b5780b3 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -1,5 +1,5 @@ name: voidstar -version: v1.38.0 # FIXME: 'git' +version: v1.39.0 # FIXME: 'git' summary: void* casts files onto 2D/3D colored spaces for your mind blowing needs # 79 char long summary description: | Usage: diff --git a/variables.bzl b/variables.bzl index 6a56ffe..20871cd 100644 --- a/variables.bzl +++ b/variables.bzl @@ -20,7 +20,7 @@ COPTS = [ "-Wstrict-overflow=4", "-Wundef", # "-Wstrict-prototypes", conlyopt - "-Wswitch-default", + # "-Wswitch-default", @fmt complains "-Wswitch-enum", ### "-fstack-protector-strong", diff --git a/voidstar/BUILD b/voidstar/BUILD index f5b8a07..8c663b4 100644 --- a/voidstar/BUILD +++ b/voidstar/BUILD @@ -26,7 +26,10 @@ cc_library( "types.h", ], copts = COPTS, - deps = [":indices"], + deps = [ + ":indices", + "@fmt", + ], ) cc_library( diff --git a/voidstar/managers/glfw3.cc b/voidstar/managers/glfw3.cc index c7d8444..a5ed162 100644 --- a/voidstar/managers/glfw3.cc +++ b/voidstar/managers/glfw3.cc @@ -2,6 +2,8 @@ // This comments prevents clang-format from reordering includes #include "voidstar/managers/glfw3.h" +#include "voidstar/size2str.h" + std::shared_ptr GLFW3Manager::instance_; void onFramebufferResize(GLFWwindow* UNUSED(window), int width, int height) { @@ -231,7 +233,7 @@ bool GLFW3Manager::updateFirst(float deltaTime, glm::mat4* MVP) { if (args_->move_window) slide_window_right(); auto slid = slide_window(scene_->selected(), scene_->indices()); if (previously_slid_ != slid) - std::cout << "#selected: " << slid << std::endl; + std::cout << "#selected: " << size2str(slid, "{:10}") << std::endl; previously_slid_ = slid; if (slid < 1 && args_->move_window) args_->move_window = false; } diff --git a/voidstar/scenes/scene.cc b/voidstar/scenes/scene.cc index dd26d61..8e107cc 100644 --- a/voidstar/scenes/scene.cc +++ b/voidstar/scenes/scene.cc @@ -1,4 +1,5 @@ #include "voidstar/scenes/scene.h" +#include "voidstar/size2str.h" REGISTRY_IMPLEMENTATION_FOR(Scene) @@ -8,3 +9,10 @@ void Scene::load(std::shared_ptr algo) { if (algo_ && algo_ != algo) std::cerr << "deleting algo\n"; algo_ = algo; } + +void Scene::resize(u32 viewport_width, u32 viewport_height) { + const float aspect_ratio = + static_cast(viewport_width) / static_cast(viewport_height); + std::cout << "aspect: " << aspect_ratio << " (" << size2str(viewport_width) + << 'x' << size2str(viewport_height) << ")\n"; +} diff --git a/voidstar/scenes/scene.h b/voidstar/scenes/scene.h index 48e97d2..3d82ecc 100644 --- a/voidstar/scenes/scene.h +++ b/voidstar/scenes/scene.h @@ -7,7 +7,6 @@ #include "voidstar/algorithm.h" #include "voidstar/arguments.h" #include "voidstar/registrar.h" -#include "voidstar/size2str.h" class Scene { public: @@ -21,12 +20,7 @@ class Scene { virtual void unload() {} virtual void reload() {} - virtual void resize(u32 viewport_width, u32 viewport_height) { - const float aspect_ratio = static_cast(viewport_width) / - static_cast(viewport_height); - std::cout << "aspect: " << aspect_ratio << " (" << size2str(viewport_width) - << 'x' << size2str(viewport_height) << ")\n"; - } + virtual void resize(u32 viewport_width, u32 viewport_height); GLint program() const { assertm(program_ <= std::numeric_limits::max(), diff --git a/voidstar/size2str.cc b/voidstar/size2str.cc index c81808a..d1e5b13 100644 --- a/voidstar/size2str.cc +++ b/voidstar/size2str.cc @@ -1,24 +1,14 @@ +#include + #include "voidstar/size2str.h" -#include +#include "fmt/format.h" /// 991337 --> "991,337" -std::string size2str(size_t size) { - const auto digits = std::ceil(std::log10(size)); - const auto nonits = static_cast(std::ceil(digits / 3) - 1); - std::string str(static_cast(digits) + nonits, '*'); - - int written = 0; - for (size_t pos = str.length() - 1; pos != 0; pos--) { - if (written != 0 && written % 3 == 0) { - str[pos] = '_'; - written = 0; - continue; - } - str[pos] = static_cast('0' + size % 10); - size /= 10; - written++; - } - if (size != 0) str[0] = static_cast('0' + size); +std::string size2str(size_t size, const std::string& format) { + std::string str = fmt::format(format, fmt::group_digits(size)); + std::replace_if( + std::begin(str), std::end(str), + [](std::string::value_type v) { return v == ','; }, '_'); return str; } diff --git a/voidstar/size2str.h b/voidstar/size2str.h index 90cb3f4..4af256b 100644 --- a/voidstar/size2str.h +++ b/voidstar/size2str.h @@ -2,4 +2,4 @@ #include -std::string size2str(size_t size); +std::string size2str(size_t size, const std::string& format = "{}");