diff options
| author | ruki <[email protected]> | 2019-09-06 22:38:17 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-09-06 09:49:43 +0800 |
| commit | e5152e174154dde4f9fdd3f49047f36c0966d7ea (patch) | |
| tree | abd39a906a05aa856dbb18b4813d9181ae8a1fdd | |
| parent | cfb90668f507c9b93fa3e53f78f8f46cdb136413 (diff) | |
impl clang modules
| -rw-r--r-- | tests/projects/c++/modules/hello/xmake.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 20 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 14 | ||||
| -rw-r--r-- | xmake/core/tool/builder.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/action/build/object.lua | 14 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua | 2 | ||||
| -rw-r--r-- | xmake/rules/c++/modules/xmake.lua | 31 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 2 |
8 files changed, 67 insertions, 19 deletions
diff --git a/tests/projects/c++/modules/hello/xmake.lua b/tests/projects/c++/modules/hello/xmake.lua index 5d94b5d15..e22047e4b 100644 --- a/tests/projects/c++/modules/hello/xmake.lua +++ b/tests/projects/c++/modules/hello/xmake.lua @@ -1,6 +1,5 @@ target("hello") set_kind("binary") - add_rules("c++.build.modules") add_files("src/*.cpp", "src/*.mpp") diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index c5a8c7322..292adacba 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -43,9 +43,10 @@ local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info) - local instance = table.inherit(_instance) - instance._NAME = name - instance._INFO = info + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._CACHEID = 1 return instance end @@ -181,6 +182,11 @@ function _instance:_check() io.flush() end +-- invalidate the previous cache key +function _instance:_invalidate() + self._CACHEID = self._CACHEID + 1 +end + -- attempt to check option function _instance:check() @@ -296,16 +302,19 @@ end -- set the value to the option info function _instance:set(name, ...) self._INFO:apival_set(name, ...) + self:_invalidate() end -- add the value to the option info function _instance:add(name, ...) self._INFO:apival_add(name, ...) + self:_invalidate() end -- remove the value to the option info function _instance:del(name, ...) self._INFO:apival_del(name, ...) + self:_invalidate() end -- get the extra configuration @@ -336,6 +345,11 @@ function _instance:name() return self._NAME end +-- get the cache key +function _instance:cachekey() + return string.format("%s_%d", tostring(self), self._CACHEID) +end + -- get xxx_script function _instance:script(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 911d8ddbf..5584ed569 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -48,6 +48,7 @@ function _instance.new(name, info, project) instance._NAME = name instance._INFO = info instance._PROJECT = project + instance._CACHEID = 1 return instance end @@ -239,6 +240,11 @@ function _instance:_visibility(opt) return visibility end +-- invalidate the previous cache key +function _instance:_invalidate() + self._CACHEID = self._CACHEID + 1 +end + -- get the target info -- -- e.g. @@ -298,16 +304,19 @@ end -- set the value to the target info function _instance:set(name, ...) self._INFO:apival_set(name, ...) + self:_invalidate() end -- add the value to the target info function _instance:add(name, ...) self._INFO:apival_add(name, ...) + self:_invalidate() end -- remove the value to the target info function _instance:del(name, ...) self._INFO:apival_del(name, ...) + self:_invalidate() end -- get the extra configuration @@ -387,6 +396,11 @@ function _instance:name() return self._NAME end +-- get the cache key +function _instance:cachekey() + return string.format("%s_%d", tostring(self), self._CACHEID) +end + -- get the target version function _instance:version() diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index f9cd6fe3d..e618f34ce 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -307,7 +307,7 @@ function builder:_add_flags_from_target(flags, target) local cache = self._TARGETFLAGS -- get flags from cache first - local key = tostring(target) + local key = target:cachekey() local targetflags = cache[key] if not targetflags then diff --git a/xmake/modules/private/action/build/object.lua b/xmake/modules/private/action/build/object.lua index 7201185ff..209d99bfe 100644 --- a/xmake/modules/private/action/build/object.lua +++ b/xmake/modules/private/action/build/object.lua @@ -56,11 +56,13 @@ function _do_build_file(target, sourcefile, opt) local exists_ccache = ccache.exists() -- trace progress info - cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) - if verbose then - cprint("${dim color.build.object}%scompiling.$(mode) %s", exists_ccache and "ccache " or "", sourcefile) - else - cprint("${color.build.object}%scompiling.$(mode) %s", exists_ccache and "ccache " or "", sourcefile) + if not opt.quiet then + cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress) + if verbose then + cprint("${dim color.build.object}%scompiling.$(mode) %s", exists_ccache and "ccache " or "", sourcefile) + else + cprint("${color.build.object}%scompiling.$(mode) %s", exists_ccache and "ccache " or "", sourcefile) + end end -- trace verbose info @@ -97,7 +99,7 @@ function _build_object(target, sourcebatch, index, opt) local progress_now = progress.start + ((index - 1) * (progress.stop - progress.start)) / #sourcebatch.sourcefiles -- init build option - local opt = {objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = progress_now, configs = opt.configs} + local opt = table.join(opt, {objectfile = objectfile, dependfile = dependfile, sourcekind = sourcekind, progress = progress_now}) -- do before build local before_build_file = target:script("build_file_before") diff --git a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua index 149330276..24310bf7d 100644 --- a/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs200x_vcproj.lua @@ -410,7 +410,7 @@ end function _make_cxfile(vcprojfile, vsinfo, target, sourcefile, objectfile, vcprojdir) -- get the target key - local key = tostring(target) + local key = target:cachekey() -- make flags cache _g.flags = _g.flags or {} diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua index 2ecb829fc..33c0bfb9c 100644 --- a/xmake/rules/c++/modules/xmake.lua +++ b/xmake/rules/c++/modules/xmake.lua @@ -21,9 +21,6 @@ -- define rule: c++.build.modules rule("c++.build.modules") set_extensions(".mpp", ".mxx", ".cppm", ".ixx") - before_load(function (target) - --target:add("cxxflags", "-fprebuilt-module-path=") - end) before_build_files(function (target, sourcebatch, opt) -- imports @@ -34,7 +31,7 @@ rule("c++.build.modules") sourcebatch.objectfiles = sourcebatch.objectfiles or {} sourcebatch.dependfiles = sourcebatch.dependfiles or {} for _, sourcefile in ipairs(sourcebatch.sourcefiles) do - local objectfile = target:objectfile(sourcefile) + local objectfile = target:objectfile(sourcefile) .. ".pcm" table.insert(sourcebatch.objectfiles, objectfile) table.insert(sourcebatch.dependfiles, target:dependfile(objectfile)) end @@ -42,10 +39,32 @@ rule("c++.build.modules") -- do compile local compinst = compiler.load("cxx") if compinst:name() == "clang" then - opt.configs = {cxxflags = {"-fmodules-ts", "--precompile"}} + + -- compile module files to *.pcm + opt = table.join(opt, {configs = {cxxflags = {"-fmodules-ts", "--precompile", "-x c++-module"}}}) + import("private.action.build.object")(target, sourcebatch, opt) + + -- compile *.pcm to object files + local modulefiles = {} + for idx, sourcefile in ipairs(sourcebatch.sourcefiles) do + local modulefile = sourcebatch.objectfiles[idx] + local objectfile = target:objectfile(sourcefile) + sourcebatch.sourcefiles[idx] = modulefile + sourcebatch.objectfiles[idx] = objectfile + sourcebatch.dependfiles[idx] = target:dependfile(objectfile) + table.insert(modulefiles, modulefile) + end + opt.configs = {cxxflags = {"-fmodules-ts"}} + opt.quiet = true + import("private.action.build.object")(target, sourcebatch, opt) + + -- add module files + target:add("cxxflags", "-fmodules-ts") + for _, modulefile in ipairs(modulefiles) do + target:add("cxxflags", "-fmodule-file=" .. modulefile) + end else raise("compiler(%s): does not support module!", compinst:name()) end - import("private.action.build.object")(target, sourcebatch, opt) end) diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index 32bd19f5b..b1263a407 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -41,7 +41,7 @@ rule("c++.build.pcheader") -- define rule: c++.build rule("c++.build") set_extensions(".cpp", ".cc", ".cxx") - add_deps("c++.build.pcheader") + add_deps("c++.build.pcheader", "c++.build.modules") on_build_files(function (target, sourcebatch, opt) import("private.action.build.object")(target, sourcebatch, opt) end) |
