File tree Expand file tree Collapse file tree 5 files changed +49
-8
lines changed
Expand file tree Collapse file tree 5 files changed +49
-8
lines changed Original file line number Diff line number Diff line change 1- def devserver (name , port ):
1+ def devserver (name , port , static_file , data = []):
2+ normalized_static_file = Label (native .repository_name () + "//" + native .package_name ()).relative (static_file )
23 native .cc_binary (
34 name = name ,
45 srcs = [
56 Label ("@rules_devserver//devserver:main" ),
67 Label ("@rules_devserver//devserver:httplib" )
78 ],
8- args = ["--port=%d" % port ],
9+ args = [
10+ "--port=%d" % port ,
11+ "--static_file=%s" % normalized_static_file
12+ ],
13+ data = data ,
14+ deps = ["@bazel_tools//tools/cpp/runfiles" ],
915 linkopts = ["-lpthread" ],
1016 )
Original file line number Diff line number Diff line change 11#include " devserver/httplib/httplib.h"
2+ #include " tools/cpp/runfiles/runfiles.h"
3+
4+ using bazel::tools::cpp::runfiles::Runfiles;
25
36int main (int argc, char **argv) {
47 httplib::Server svr;
58 std::string port = " 8080" ;
69
10+ std::string runfiles_error;
11+ std::unique_ptr<Runfiles> runfiles (
12+ Runfiles::Create (argv[0 ], BAZEL_CURRENT_REPOSITORY, &runfiles_error));
13+
14+ std::string path = runfiles->Rlocation (" devserver/" );
15+ std::cout << " path: " << path << std::endl;
16+
17+ // print all args
18+ for (int i = 0 ; i < argc; i++) {
19+ std::cout << " argv[" << i << " ] = " << argv[i] << std::endl;
20+ }
21+
722 for (int i = 0 ; i < argc; i++) {
823 if (std::string (argv[i]).rfind (" --port" , 0 ) != std::string::npos) {
924 port = std::string (argv[i]).substr (7 );
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ load ("//devserver:defs.bzl" , "devserver" )
2+
3+ filegroup (
4+ name = "index" ,
5+ srcs = ["index.html" ],
6+ visibility = ["//visibility:public" ],
7+ )
8+
9+ devserver (
10+ name = "serve" ,
11+ port = 8081 ,
12+ static_file = ":index" ,
13+ data = [":index" ],
14+ )
Original file line number Diff line number Diff line change 1+ < html >
2+
3+ < head >
4+ < title > Single Static File</ title >
5+ </ head >
6+
7+ < body >
8+ < h1 > Single Static File</ h1 >
9+ < p > This is a single static file.</ p >
10+ </ body >
11+
12+ </ html >
You can’t perform that action at this time.
0 commit comments