server/rccpp, server/state: Supply cxxflags and ldflags from deps.txt to compiler
This commit is contained in:
parent
b4645bb7a5
commit
99bfd2c53a
@ -63,8 +63,6 @@ File format: One entry per line. Indentation for presentational purposes only.
|
|||||||
|
|
||||||
Module entry:
|
Module entry:
|
||||||
module:<module_name> <options>
|
module:<module_name> <options>
|
||||||
Extension entry:
|
|
||||||
extension:<extension_name> <options>
|
|
||||||
Extra CXXFLAGS:
|
Extra CXXFLAGS:
|
||||||
cxxflags:<flags>
|
cxxflags:<flags>
|
||||||
Extra LDFLAGS:
|
Extra LDFLAGS:
|
||||||
@ -72,13 +70,12 @@ Extra LDFLAGS:
|
|||||||
|
|
||||||
Options:
|
Options:
|
||||||
? - Optional dependency
|
? - Optional dependency
|
||||||
r - Reverse dependency; load before the specified module (not for extensions)
|
r - Reverse dependency; load before the specified module
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
module:network
|
module:network
|
||||||
module:plants ?
|
module:plants ?
|
||||||
module:stuff ?r
|
module:stuff ?r
|
||||||
extension:ecs2
|
|
||||||
ldflags:-lsasl2
|
ldflags:-lsasl2
|
||||||
|
|
||||||
Extension structure
|
Extension structure
|
||||||
|
@ -33,7 +33,8 @@ struct CCompiler: public Compiler
|
|||||||
CCompiler();
|
CCompiler();
|
||||||
|
|
||||||
bool build(const std::string &module_name,
|
bool build(const std::string &module_name,
|
||||||
const std::string &in_path, const std::string &out_path);
|
const std::string &in_path, const std::string &out_path,
|
||||||
|
const ss_ &extra_cxxflags="", const ss_ &extra_ldflags="");
|
||||||
|
|
||||||
void* construct(const char *name, interface::Server *server);
|
void* construct(const char *name, interface::Server *server);
|
||||||
|
|
||||||
@ -42,7 +43,8 @@ struct CCompiler: public Compiler
|
|||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, RCCPP_Info> m_module_info;
|
std::unordered_map<std::string, RCCPP_Info> m_module_info;
|
||||||
|
|
||||||
bool compile(const std::string &in_path, const std::string &out_path);
|
bool compile(const std::string &in_path, const std::string &out_path,
|
||||||
|
const ss_ &extra_cxxflags="", const ss_ &extra_ldflags="");
|
||||||
};
|
};
|
||||||
|
|
||||||
// linux
|
// linux
|
||||||
@ -72,12 +74,17 @@ CCompiler::CCompiler()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCompiler::compile(const std::string &in_path, const std::string &out_path)
|
bool CCompiler::compile(const std::string &in_path, const std::string &out_path,
|
||||||
|
const ss_ &extra_cxxflags, const ss_ &extra_ldflags)
|
||||||
{
|
{
|
||||||
//std::string command = "g++ -g -O0 -fPIC -fvisibility=hidden -shared";
|
//std::string command = "g++ -g -O0 -fPIC -fvisibility=hidden -shared";
|
||||||
std::string command = "g++ -DRCCPP -g -fPIC -fvisibility=hidden -shared";
|
std::string command = "g++ -DRCCPP -g -fPIC -fvisibility=hidden -shared";
|
||||||
|
|
||||||
command += " -std=c++11";
|
command += " -std=c++11";
|
||||||
|
if(extra_cxxflags != "")
|
||||||
|
command += ss_()+" "+extra_cxxflags;
|
||||||
|
if(extra_ldflags != "")
|
||||||
|
command += ss_()+" "+extra_ldflags;
|
||||||
|
|
||||||
for(const std::string &dir : include_directories) command += " -I"+dir;
|
for(const std::string &dir : include_directories) command += " -I"+dir;
|
||||||
for(const std::string &dir : library_directories) command += " -L"+dir;
|
for(const std::string &dir : library_directories) command += " -L"+dir;
|
||||||
@ -101,7 +108,8 @@ bool CCompiler::compile(const std::string &in_path, const std::string &out_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CCompiler::build(const std::string &module_name,
|
bool CCompiler::build(const std::string &module_name,
|
||||||
const std::string &in_path, const std::string &out_path)
|
const std::string &in_path, const std::string &out_path,
|
||||||
|
const ss_ &extra_cxxflags, const ss_ &extra_ldflags)
|
||||||
{
|
{
|
||||||
log_ni(MODULE, "Building %s: %s -> %s... ", cs(module_name), cs(in_path),
|
log_ni(MODULE, "Building %s: %s -> %s... ", cs(module_name), cs(in_path),
|
||||||
cs(out_path));
|
cs(out_path));
|
||||||
@ -109,7 +117,7 @@ bool CCompiler::build(const std::string &module_name,
|
|||||||
std::string out_dir = c55fs::stripFilename(out_path);
|
std::string out_dir = c55fs::stripFilename(out_path);
|
||||||
c55fs::CreateAllDirs(out_dir);
|
c55fs::CreateAllDirs(out_dir);
|
||||||
|
|
||||||
if(!compile(in_path, out_path)){
|
if(!compile(in_path, out_path, extra_cxxflags, extra_ldflags)){
|
||||||
log_i(MODULE, "Failed!");
|
log_i(MODULE, "Failed!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,8 @@ namespace rccpp
|
|||||||
virtual ~Compiler(){}
|
virtual ~Compiler(){}
|
||||||
|
|
||||||
virtual bool build(const std::string &module_name,
|
virtual bool build(const std::string &module_name,
|
||||||
const std::string &in_path, const std::string &out_path) = 0;
|
const std::string &in_path, const std::string &out_path,
|
||||||
|
const ss_ &extra_cxxflags="", const ss_ &extra_ldflags="") = 0;
|
||||||
|
|
||||||
virtual void* construct(const char *name, interface::Server *server) = 0;
|
virtual void* construct(const char *name, interface::Server *server) = 0;
|
||||||
|
|
||||||
|
@ -62,6 +62,33 @@ static sv_<ss_> list_includes(const ss_ &path, const sv_<ss_> &include_dirs)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DepLine {
|
||||||
|
ss_ type;
|
||||||
|
ss_ value;
|
||||||
|
ss_ options;
|
||||||
|
};
|
||||||
|
static sv_<DepLine> get_deps(const ss_ &depfile_path)
|
||||||
|
{
|
||||||
|
sv_<DepLine> result;
|
||||||
|
std::ifstream ifs(depfile_path);
|
||||||
|
if(!ifs.good())
|
||||||
|
return result;
|
||||||
|
ss_ line;
|
||||||
|
while(std::getline(ifs, line)){
|
||||||
|
c55::Strfnd f(line);
|
||||||
|
DepLine dep;
|
||||||
|
dep.type = f.next(":");
|
||||||
|
if(dep.type == "module"){
|
||||||
|
dep.value = f.next(" ");
|
||||||
|
dep.options = f.next("");
|
||||||
|
} else {
|
||||||
|
dep.value = f.next("");
|
||||||
|
}
|
||||||
|
result.push_back(dep);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
struct CState: public State, public interface::Server
|
struct CState: public State, public interface::Server
|
||||||
{
|
{
|
||||||
struct ModuleContainer {
|
struct ModuleContainer {
|
||||||
@ -137,6 +164,7 @@ struct CState: public State, public interface::Server
|
|||||||
sv_<ss_> includes = list_includes(init_cpp_path, include_dirs);
|
sv_<ss_> includes = list_includes(init_cpp_path, include_dirs);
|
||||||
log_i(MODULE, "Includes: %s", cs(dump(includes)));
|
log_i(MODULE, "Includes: %s", cs(dump(includes)));
|
||||||
files_to_watch.insert(files_to_watch.end(), includes.begin(), includes.end());
|
files_to_watch.insert(files_to_watch.end(), includes.begin(), includes.end());
|
||||||
|
|
||||||
if(m_module_file_watches.count(module_name) == 0){
|
if(m_module_file_watches.count(module_name) == 0){
|
||||||
m_module_file_watches[module_name] = sp_<interface::FileWatch>(
|
m_module_file_watches[module_name] = sp_<interface::FileWatch>(
|
||||||
interface::createFileWatch(files_to_watch,
|
interface::createFileWatch(files_to_watch,
|
||||||
@ -152,8 +180,21 @@ struct CState: public State, public interface::Server
|
|||||||
|
|
||||||
// Build
|
// Build
|
||||||
|
|
||||||
|
sv_<DepLine> deps = get_deps(path+"/deps.txt");
|
||||||
|
ss_ extra_cxxflags;
|
||||||
|
ss_ extra_ldflags;
|
||||||
|
for(const DepLine &dep : deps){
|
||||||
|
if(dep.type == "cxxflags")
|
||||||
|
extra_cxxflags += dep.value+" ";
|
||||||
|
if(dep.type == "ldflags")
|
||||||
|
extra_ldflags += dep.value+" ";
|
||||||
|
}
|
||||||
|
log_i(MODULE, "extra_cxxflags: %s", cs(extra_cxxflags));
|
||||||
|
log_i(MODULE, "extra_ldflags: %s", cs(extra_ldflags));
|
||||||
|
|
||||||
m_compiler->include_directories.push_back(m_modules_path);
|
m_compiler->include_directories.push_back(m_modules_path);
|
||||||
bool build_ok = m_compiler->build(module_name, init_cpp_path, build_dst);
|
bool build_ok = m_compiler->build(module_name, init_cpp_path, build_dst,
|
||||||
|
extra_cxxflags, extra_ldflags);
|
||||||
m_compiler->include_directories.pop_back();
|
m_compiler->include_directories.pop_back();
|
||||||
|
|
||||||
if(!build_ok){
|
if(!build_ok){
|
||||||
|
1
todo.txt
1
todo.txt
@ -5,4 +5,3 @@ Buildat TODO
|
|||||||
- Modules should be run in threads.
|
- Modules should be run in threads.
|
||||||
- Implement module depencencies in test/testmodules/__loader
|
- Implement module depencencies in test/testmodules/__loader
|
||||||
- There should probably be a builtin/loader that __loader usually wants to call
|
- There should probably be a builtin/loader that __loader usually wants to call
|
||||||
- Implement deps.txt cxxflags and ldflags
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user