Skip to content

Commit

Permalink
move one header out of a much included header (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Jan 3, 2022
1 parent 32096f4 commit 8bd8b60
Show file tree
Hide file tree
Showing 11 changed files with 128 additions and 42 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
85 changes: 73 additions & 12 deletions resolved.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": "",
Expand All @@ -285,7 +346,7 @@ resolved = [
"tag": "",
"name": "glfw",
},
"output_tree_hash": "4b56c95d240132034ba6f6016e8763b9aabd101aabf9ea500f8a432da64ceb8e",
"output_tree_hash": "88ebe8b7b6a3c0003e4c079267eeeaa1b345ce5b475396952d576275b824e9f6",
},
],
},
Expand All @@ -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": "",
Expand All @@ -328,7 +389,7 @@ resolved = [
"tag": "~3",
"name": "glfw_osx",
},
"output_tree_hash": "8bfd001632546166c2d147f2921c40a105029eef8d05166ddce756a01174e125",
"output_tree_hash": "92f15c4c1dee77f2824d3b190160e405da7bd466e07864e58ee07800da1fde01",
},
],
},
Expand Down Expand Up @@ -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": "",
Expand All @@ -409,7 +470,7 @@ resolved = [
"tag": "",
"name": "khronos_opengl_registry",
},
"output_tree_hash": "bf605749708e8158d41aa39c943da121e5028b653edb2583fb0c5d41397f3c6a",
"output_tree_hash": "b9d1b80b21b961ef1c7f83dd3ddb13ce72f521a39a51c96751e1b8c6a932750a",
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion variables.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ COPTS = [
"-Wstrict-overflow=4",
"-Wundef",
# "-Wstrict-prototypes", conlyopt
"-Wswitch-default",
# "-Wswitch-default", @fmt complains
"-Wswitch-enum",
###
"-fstack-protector-strong",
Expand Down
5 changes: 4 additions & 1 deletion voidstar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ cc_library(
"types.h",
],
copts = COPTS,
deps = [":indices"],
deps = [
":indices",
"@fmt",
],
)

cc_library(
Expand Down
4 changes: 3 additions & 1 deletion voidstar/managers/glfw3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> GLFW3Manager::instance_;

void onFramebufferResize(GLFWwindow* UNUSED(window), int width, int height) {
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions voidstar/scenes/scene.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "voidstar/scenes/scene.h"
#include "voidstar/size2str.h"

REGISTRY_IMPLEMENTATION_FOR(Scene)

Expand All @@ -8,3 +9,10 @@ void Scene::load(std::shared_ptr<Algorithm> 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<float>(viewport_width) / static_cast<float>(viewport_height);
std::cout << "aspect: " << aspect_ratio << " (" << size2str(viewport_width)
<< 'x' << size2str(viewport_height) << ")\n";
}
8 changes: 1 addition & 7 deletions voidstar/scenes/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "voidstar/algorithm.h"
#include "voidstar/arguments.h"
#include "voidstar/registrar.h"
#include "voidstar/size2str.h"

class Scene {
public:
Expand All @@ -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<float>(viewport_width) /
static_cast<float>(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<GLint>::max(),
Expand Down
26 changes: 8 additions & 18 deletions voidstar/size2str.cc
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
#include <algorithm>

#include "voidstar/size2str.h"

#include <cmath>
#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<size_t>(std::ceil(digits / 3) - 1);
std::string str(static_cast<size_t>(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<char>('0' + size % 10);
size /= 10;
written++;
}
if (size != 0) str[0] = static_cast<char>('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;
}
2 changes: 1 addition & 1 deletion voidstar/size2str.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <string>

std::string size2str(size_t size);
std::string size2str(size_t size, const std::string& format = "{}");

0 comments on commit 8bd8b60

Please sign in to comment.