Skip to content

Commit 9783efc

Browse files
committed
Working hello example with icu
1 parent 0288c23 commit 9783efc

7 files changed

Lines changed: 155 additions & 85 deletions

File tree

.bazelrc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ common --enable_bzlmod
88
# common --process_headers_in_dependencies
99
# common --enable_platform_specific_config
1010

11-
build --cxxopt='-std=c++17'
12-
# build --incompatible_disallow_empty_glob
11+
build --cxxopt=-std=c++17
12+
build --incompatible_disallow_empty_glob=false
1313
# build --verbose_failures
1414
# build --worker_sandboxing
1515
# build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
1616

1717
# build:linux --sandbox_add_mount_pair=/tmp
1818
# build:macos --sandbox_add_mount_pair=/var/tmp
1919
# build:windows --sandbox_add_mount_pair=C:\Temp
20-
#
20+
#
2121
# test --sandbox_default_allow_network=false
2222
# test --test_output=errors
23+
24+
build:asan --strip=never -c dbg
25+
build:asan --copt=-fsanitize=address
26+
build:asan --copt=-O1
27+
build:asan --copt=-fno-omit-frame-pointer
28+
build:asan --linkopt=-fsanitize=address

BUILD.bazel

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@ cc_library(
125125
visibility = ["//visibility:public"],
126126
deps = [
127127
# "@pcre2",
128-
"@icu",
128+
"@icu//icu4c/source/i18n:headers",
129+
"@icu//icu4c/source/i18n:collation",
130+
"@icu//icu4c/source/common:breakiterator",
131+
"@icu//icu4c/source/common:platform",
132+
"@icu//icu4c/source/common:uniset",
129133
# "@zlib",
130134
],
131135
)
@@ -259,7 +263,8 @@ cc_library(
259263
linkstatic = True,
260264
visibility = ["//visibility:public"],
261265
deps = [
262-
"@icu",
266+
"@icu//icu4c/source/common:breakiterator",
267+
"@icu//icu4c/source/common:uniset",
263268
"//:booster",
264269
"@boringssl//:crypto",
265270
"@boringssl//:ssl",

MODULE.bazel

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ bazel_dep(name = "aspect_rules_ts", version = "1.4.5")
1010
bazel_dep(name = "zlib", version = "1.3.1.bcr.3")
1111
bazel_dep(name = "pcre2", version = "10.43")
1212
bazel_dep(name = "rules_python", version = "0.36.0")
13+
bazel_dep(name = "icu", version = "76.1.bcr.3")
14+
15+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
16+
17+
http_archive(
18+
name = "icu_dat",
19+
urls = ["https://github.com/unicode-org/icu/releases/download/release-76-1/icu4c-76_1-src.tgz"],
20+
strip_prefix = "icu",
21+
build_file_content = """filegroup(
22+
name = "icu_dat",
23+
srcs = ["source/data/in/icudt76l.dat"],
24+
visibility = ["//visibility:public"],
25+
)""",
26+
)
27+
1328

1429
# bazel_dep(name = "boringssl", version = "0.20240913.0", repo_name = "openssl")
1530
bazel_dep(name = "boringssl", version = "0.20240913.0")
@@ -40,56 +55,38 @@ git_override(
4055
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
4156
)
4257

43-
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44-
4558
#####################################################################
46-
# icu library
59+
# toolchain_llvm
4760
#####################################################################
4861

49-
http_archive(
50-
name = "icu",
51-
build_file = "@cppcms_workspace//third_party:BUILD.icu.bazel",
52-
strip_prefix = "icu",
53-
urls = ["https://github.com/unicode-org/icu/releases/download/release-75-1/icu4c-75_1-src.tgz"],
54-
patch_args = ["-p1"],
55-
patches = [
56-
"@cppcms_workspace//third_party:icu-source-common.patch",
57-
"@cppcms_workspace//third_party:icu-source-icudefs.patch",
58-
"@cppcms_workspace//third_party:icu-source-data-unidata-norm2.patch",
59-
"@cppcms_workspace//third_party:icu-source-i18n.patch",
60-
"@cppcms_workspace//third_party:icu-source-stubdata.patch",
61-
"@cppcms_workspace//third_party:icu-source-tools-gennorm2.patch",
62-
"@cppcms_workspace//third_party:icu-source-tools-toolutil.patch",
63-
],
64-
)
62+
bazel_dep(name = "toolchains_llvm", version = "1.5.0")
6563

66-
#####################################################################
67-
# toolchains_llvm
68-
#####################################################################
64+
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
6965

70-
# bazel_dep(name = "toolchains_llvm", version = "1.2.0")
66+
LLVM_VERSIONS = {
67+
"": "20.1.0",
68+
}
7169

72-
#####################################################################
73-
# hermetic cc toolchain
74-
#####################################################################
75-
76-
bazel_dep(name = "hermetic_cc_toolchain", version = "3.1.1")
70+
llvm.toolchain(
71+
name = "llvm_toolchain",
72+
cxx_standard = {"": "c++2c"},
73+
llvm_versions = LLVM_VERSIONS,
74+
)
7775

78-
zig_toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
79-
use_repo(zig_toolchains, "zig_sdk")
76+
# llvm.extra_target_compatible_with(
77+
# name = "llvm_toolchain",
78+
# constraints = ["@//:cxx11"],
79+
# )
80+
use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")
8081

81-
register_toolchains(
82-
# "@zig_sdk//toolchain:linux_amd64_gnu.2.32",
83-
"@zig_sdk//toolchain:linux_amd64_gnu.2.31",
84-
# "@zig_sdk//libc_aware/toolchain:x86_64-linux-gnu.2.34",
85-
)
82+
register_toolchains("@llvm_toolchain//:all")
8683

8784
#####################################################################
8885
# other
8986
#####################################################################
9087

91-
bazel_dep(name = "rules_cc", version = "0.0.9")
92-
bazel_dep(name = "platforms", version = "0.0.10")
88+
bazel_dep(name = "rules_cc", version = "0.1.1")
89+
bazel_dep(name = "platforms", version = "0.0.11")
9390
bazel_dep(name = "rules_proto", version = "6.0.2")
9491
bazel_dep(name = "nlohmann_json", version = "3.11.3")
9592
bazel_dep(name = "spdlog", version = "1.14.1")

examples/sessions/BUILD.bazel

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ cc_library(
1919
cc_binary(
2020
name = "hello",
2121
srcs = ["hello.cpp", "view.cpp"],
22-
data = ["config.js"],
22+
data = [
23+
"config.js",
24+
"@icu_dat//:icu_dat",
25+
],
26+
cxxopts = [
27+
"-std=c++2c",
28+
],
2329
deps = [
2430
"//:cppcms_lib",
2531
":view_lib",
26-
"@icu",
32+
"@icu//icu4c/source/common:breakiterator",
33+
"@icu//icu4c/source/i18n:collation",
34+
"@icu//icu4c/source/common:uniset",
2735
"//:booster",
36+
"@icu//icu4c/source/common:platform",
37+
"@rules_cc//cc/runfiles",
2838
"@zlib",
2939
],
3040
)

examples/sessions/config.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
{
2+
"app": {
3+
"root": ""
4+
},
5+
"localization": {
6+
"locales": [
7+
"bg_BG.UTF-8"
8+
]
9+
},
10+
"logging": {
11+
"level": "debug"
12+
},
13+
"security": {
14+
"content_length_limit": 102400,
15+
"multipart_form_data_limit": 102400
16+
},
217
"service" : {
318
"api" : "http",
4-
"port" : 8080
19+
"port" : 8882,
20+
"ip" : "0.0.0.0"
21+
// "port" : 8080
522
},
623
"http" : {
7-
"script" : "/hello"
24+
"script" : "/hello",
25+
"script_names" : [ "/hello" ]
826
},
9-
"session" : {
10-
"expire" : "renew",
11-
"timeout" : 604800,
12-
"location" : "client",
13-
"client" : {
14-
"hmac" : "sha1",
15-
"hmac_key" : "3891bbf7f845fd4277008a63d72640fc13bb9a31"
16-
}
17-
}
27+
"session": {
28+
"client": {
29+
"hmac": "md5",
30+
"hmac_key": "a15e33bbea5d62c91191892035cb4e74874006d1"
31+
},
32+
"cookies": {
33+
"domain": "mladenov.dev",
34+
"prefix": "docs_bg_session",
35+
"secure": true
36+
},
37+
"expire": "renew",
38+
"location": "client",
39+
"timeout": 1800
40+
}
1841
}

examples/sessions/content.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef CONTENT_H
2-
#define CONTENT_H
1+
#pragma once
32

43
#include <cppcms/view.h>
54
#include <cppcms/form.h>
@@ -54,7 +53,3 @@ struct message : public cppcms::base_content {
5453
};
5554

5655
} // content
57-
58-
59-
#endif
60-
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4

examples/sessions/hello.cpp

Lines changed: 58 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,98 @@
44
#include <cppcms/service.h>
55
#include <cppcms/session_interface.h>
66
#include <cppcms/url_dispatcher.h>
7+
#include <cppcms/url_mapper.h>
8+
#include <print>
79

810
#include <iostream>
911

1012
#include "content.h"
13+
#include "rules_cc/cc/runfiles/runfiles.h"
14+
15+
#include <unicode/brkiter.h>
1116

1217
using namespace std;
18+
using rules_cc::cc::runfiles::Runfiles;
1319

1420
class hello : public cppcms::application {
1521
public:
16-
hello(cppcms::service &s) : cppcms::application(s) {}
17-
void mainRaw(std::string /*url*/) {
22+
hello(cppcms::service &s) : cppcms::application{s} {
23+
std::println("{} app.root: {}", "constructed",
24+
settings().get<std::string>("app.root"));
25+
dispatcher().assign("/number/(\\d+)",&hello::number,this,1);
26+
mapper().assign("number","/number/{1}");
27+
dispatcher().assign("/mainRaw",&hello::mainRaw,this);
28+
mapper().assign("mainRaw","/mainRaw");
29+
dispatcher().assign("/",&hello::root,this);
30+
mapper().assign("/");
31+
mapper().root("/hello");
32+
// mapper().root(settings().get<std::string>("app.root"));
33+
}
34+
void number(std::string num)
35+
{
36+
std::println("{}", " in the number");
37+
int no = atoi(num.c_str());
38+
response().out() << "The number is " << no << "<br/>\n";
39+
response().out() << "<a href='" << url("/") << "'>Go back</a>";
40+
}
41+
void mainRaw() {
1842
response().out() << "<html>\n"
1943
"<body>\n"
20-
" <h1>Hello World</h1>\n"
44+
" <h1>Hello ----- World</h1>\n"
2145
"</body>\n"
2246
"</html>\n";
2347
}
24-
void main(std::string /* unused */) {
48+
virtual void root();
49+
};
50+
51+
52+
void hello::root() {
53+
std::println("{}", " inside the main");
2554
content::message c;
2655
// c.app(this);
2756
if (request().request_method() == "POST") {
28-
c.info.load(context());
29-
if (c.info.validate()) {
57+
c.info.load(context());
58+
if (c.info.validate()) {
3059
session()["name"] = c.info.name.value();
3160
session()["sex"] = c.info.sex.selected_id();
3261
session()["state"] = c.info.martial.selected_id();
3362
session().set("age", c.info.age.value());
3463
c.info.clear();
35-
}
64+
}
3665
}
37-
3866
if (session().is_set("name")) {
39-
c.name = session()["name"];
40-
if (session()["sex"] == "m") {
67+
c.name = session()["name"];
68+
if (session()["sex"] == "m") {
4169
c.who = "Mr";
42-
} else {
70+
} else {
4371
if (session()["state"] == "s") {
44-
c.who = "Miss";
72+
c.who = "Miss";
4573
} else {
46-
c.who = "Mrs";
74+
c.who = "Mrs";
75+
}
4776
}
48-
}
49-
c.age = session().get<double>("age");
77+
c.age = session().get<double>("age");
5078
} else {
51-
c.name = "Visitor";
52-
c.age = -1;
79+
c.name = "Visitor";
80+
c.age = -1;
5381
}
5482
render("message", c);
55-
}
56-
};
83+
}
5784

5885
int main(int argc, char **argv) {
86+
std::unique_ptr<Runfiles> runfiles(Runfiles::Create(argv[0]));
87+
std::string path = runfiles->Rlocation("icu_dat/source/data/in/");
88+
u_setDataDirectory(path.c_str());
89+
90+
std::println("{}", " in the main");
5991
try {
60-
cppcms::service app(argc, argv);
61-
app.applications_pool().mount(cppcms::applications_factory<hello>());
62-
app.run();
92+
cppcms::service srv(argc, argv);
93+
std::println("{}", " service is ready");
94+
srv.applications_pool().mount(cppcms::applications_factory<hello>());
95+
std::println("{}", "pool mounted");
96+
srv.run();
97+
std::println("{}", "finished running");
6398
} catch (std::exception const &e) {
6499
cerr << e.what() << endl;
65100
}
66-
}
67-
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
101+
}

0 commit comments

Comments
 (0)