summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-09-07 21:54:53 +0800
committerruki <[email protected]>2019-09-07 21:54:53 +0800
commitf1cb1eb4d5d3e8a603f5e839d8859ab2fa95dfb6 (patch)
treef81a3c702a5f1e978813cfbae3eb4665c93ef04f
parent16350d2759319d15c4800e8c2a4184a34ab92171 (diff)
improve rules
-rw-r--r--xmake/rules/asm/xmake.lua4
-rw-r--r--xmake/rules/c++/modules/build_modulefiles.lua104
-rw-r--r--xmake/rules/c++/modules/xmake.lua73
-rw-r--r--xmake/rules/c++/xmake.lua8
-rw-r--r--xmake/rules/dlang/xmake.lua4
-rw-r--r--xmake/rules/go/xmake.lua4
-rw-r--r--xmake/rules/objc++/xmake.lua8
-rw-r--r--xmake/rules/rust/xmake.lua4
-rw-r--r--xmake/rules/swift/xmake.lua4
-rw-r--r--xmake/rules/winsdk/xmake.lua4
10 files changed, 115 insertions, 102 deletions
diff --git a/xmake/rules/asm/xmake.lua b/xmake/rules/asm/xmake.lua
index 3a7e85f59..9adc87ab7 100644
--- a/xmake/rules/asm/xmake.lua
+++ b/xmake/rules/asm/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: asm.build
rule("asm.build")
set_extensions(".s", ".asm")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: asm
rule("asm")
diff --git a/xmake/rules/c++/modules/build_modulefiles.lua b/xmake/rules/c++/modules/build_modulefiles.lua
new file mode 100644
index 000000000..427057814
--- /dev/null
+++ b/xmake/rules/c++/modules/build_modulefiles.lua
@@ -0,0 +1,104 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file build_modulefiles.lua
+--
+
+-- imports
+import("core.tool.compiler")
+
+-- build module files using clang
+function _build_modulefiles_clang(target, sourcebatch, opt)
+
+ -- attempt to compile the module files as cxx
+ sourcebatch.sourcekind = "cxx"
+ sourcebatch.objectfiles = sourcebatch.objectfiles or {}
+ sourcebatch.dependfiles = sourcebatch.dependfiles or {}
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local objectfile = target:objectfile(sourcefile) .. ".pcm"
+ table.insert(sourcebatch.objectfiles, objectfile)
+ table.insert(sourcebatch.dependfiles, target:dependfile(objectfile))
+ end
+
+ -- 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
+end
+
+-- build module files using msvc
+function _build_modulefiles_msvc(target, sourcebatch, opt)
+
+ -- attempt to compile the module files as cxx
+ local modulefiles = {}
+ opt = table.join(opt, {configs = {}})
+ sourcebatch.sourcekind = "cxx"
+ sourcebatch.objectfiles = sourcebatch.objectfiles or {}
+ sourcebatch.dependfiles = sourcebatch.dependfiles or {}
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ local objectfile = target:objectfile(sourcefile)
+ local dependfile = target:dependfile(objectfile)
+ local modulefile = objectfile .. ".pcm"
+
+ -- compile module file to *.pcm
+ local singlebatch = {sourcekind = "cxx", sourcefiles = {sourcefile}, objectfiles = {objectfile}, dependfiles = {dependfile}}
+ opt.configs.cxxflags = {"/experimental:module /module:interface /module:output " .. os.args(modulefile), "/TP"}
+ import("private.action.build.object")(target, singlebatch, opt)
+ table.insert(modulefiles, modulefile)
+ table.insert(sourcebatch.objectfiles, objectfile)
+ table.insert(sourcebatch.dependfiles, dependfile)
+ end
+
+ -- add module files
+ for _, modulefile in ipairs(modulefiles) do
+ target:add("cxxflags", "/experimental:module /module:reference " .. os.args(modulefile))
+ end
+end
+
+-- build module files
+function main(target, sourcebatch, opt)
+
+ -- do compile
+ local compinst = compiler.load("cxx")
+ if compinst:name() == "clang" and compinst:has_flags("-fmodules-ts") then
+ _build_modulefiles_clang(target, sourcebatch, opt)
+ elseif compinst:name() == "cl" and compinst:has_flags("/experimental:module") then
+ _build_modulefiles_msvc(target, sourcebatch, opt)
+ else
+ raise("compiler(%s): does not support module!", compinst:name())
+ end
+end
+
diff --git a/xmake/rules/c++/modules/xmake.lua b/xmake/rules/c++/modules/xmake.lua
index 5cf5517cb..29f0b28f7 100644
--- a/xmake/rules/c++/modules/xmake.lua
+++ b/xmake/rules/c++/modules/xmake.lua
@@ -21,76 +21,5 @@
-- define rule: c++.build.modules
rule("c++.build.modules")
set_extensions(".mpp", ".mxx", ".cppm", ".ixx")
- before_build_files(function (target, sourcebatch, opt)
-
- -- imports
- import("core.tool.compiler")
-
- -- do compile
- local compinst = compiler.load("cxx")
- if compinst:name() == "clang" and compinst:has_flags("-fmodules-ts") then
-
- -- attempt to compile the module files as cxx
- sourcebatch.sourcekind = "cxx"
- sourcebatch.objectfiles = sourcebatch.objectfiles or {}
- sourcebatch.dependfiles = sourcebatch.dependfiles or {}
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local objectfile = target:objectfile(sourcefile) .. ".pcm"
- table.insert(sourcebatch.objectfiles, objectfile)
- table.insert(sourcebatch.dependfiles, target:dependfile(objectfile))
- end
-
- -- 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
- elseif compinst:name() == "cl" and compinst:has_flags("/experimental:module") then
-
- -- attempt to compile the module files as cxx
- local modulefiles = {}
- opt = table.join(opt, {configs = {}})
- sourcebatch.sourcekind = "cxx"
- sourcebatch.objectfiles = sourcebatch.objectfiles or {}
- sourcebatch.dependfiles = sourcebatch.dependfiles or {}
- for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
- local objectfile = target:objectfile(sourcefile)
- local dependfile = target:dependfile(objectfile)
- local modulefile = objectfile .. ".pcm"
-
- -- compile module file to *.pcm
- local singlebatch = {sourcekind = "cxx", sourcefiles = {sourcefile}, objectfiles = {objectfile}, dependfiles = {dependfile}}
- opt.configs.cxxflags = {"/experimental:module /module:interface /module:output " .. os.args(modulefile), "/TP"}
- import("private.action.build.object")(target, singlebatch, opt)
- table.insert(modulefiles, modulefile)
- table.insert(sourcebatch.objectfiles, objectfile)
- table.insert(sourcebatch.dependfiles, dependfile)
- end
-
- -- add module files
- for _, modulefile in ipairs(modulefiles) do
- target:add("cxxflags", "/experimental:module /module:reference " .. os.args(modulefile))
- end
- else
- raise("compiler(%s): does not support module!", compinst:name())
- end
- end)
+ before_build_files("build_modulefiles")
diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua
index b1263a407..cb5f5b43c 100644
--- a/xmake/rules/c++/xmake.lua
+++ b/xmake/rules/c++/xmake.lua
@@ -28,9 +28,7 @@ rule("c.build.pcheader")
rule("c.build")
set_extensions(".c")
add_deps("c.build.pcheader")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: c++.build.pcheader
rule("c++.build.pcheader")
@@ -42,9 +40,7 @@ rule("c++.build.pcheader")
rule("c++.build")
set_extensions(".cpp", ".cc", ".cxx")
add_deps("c++.build.pcheader", "c++.build.modules")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: cpp
rule("c++")
diff --git a/xmake/rules/dlang/xmake.lua b/xmake/rules/dlang/xmake.lua
index 27f06c432..95615a3ec 100644
--- a/xmake/rules/dlang/xmake.lua
+++ b/xmake/rules/dlang/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: dlang.build
rule("dlang.build")
set_extensions(".d")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: dlang
rule("dlang")
diff --git a/xmake/rules/go/xmake.lua b/xmake/rules/go/xmake.lua
index 97d929e08..2830ce6fb 100644
--- a/xmake/rules/go/xmake.lua
+++ b/xmake/rules/go/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: go.build
rule("go.build")
set_extensions(".go")
- on_build_files(function (target, sourcebatch, opt)
- import("build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("build.object")
-- define rule: cpp
rule("go")
diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua
index e666d8b38..7356cf36d 100644
--- a/xmake/rules/objc++/xmake.lua
+++ b/xmake/rules/objc++/xmake.lua
@@ -22,17 +22,13 @@
rule("objc.build")
set_extensions(".m")
add_deps("c.build.pcheader")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: objc++.build
rule("objc++.build")
set_extensions(".mm")
add_deps("c++.build.pcheader")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: objc
rule("objc++")
diff --git a/xmake/rules/rust/xmake.lua b/xmake/rules/rust/xmake.lua
index 3d88f2c96..50ad79a89 100644
--- a/xmake/rules/rust/xmake.lua
+++ b/xmake/rules/rust/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: rust.build
rule("rust.build")
set_extensions(".rs")
- on_build(function (target, opt)
- import("build.target")(target, opt)
- end)
+ on_build("build.target")
-- define rule: cpp
rule("rust")
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 9be96096d..04fbfbcab 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: swift.build
rule("swift.build")
set_extensions(".swift")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: swift
rule("swift")
diff --git a/xmake/rules/winsdk/xmake.lua b/xmake/rules/winsdk/xmake.lua
index 66accd6aa..1cfad7a21 100644
--- a/xmake/rules/winsdk/xmake.lua
+++ b/xmake/rules/winsdk/xmake.lua
@@ -21,9 +21,7 @@
-- define rule: win.sdk.resource
rule("win.sdk.resource")
set_extensions(".rc")
- on_build_files(function (target, sourcebatch, opt)
- import("private.action.build.object")(target, sourcebatch, opt)
- end)
+ on_build_files("private.action.build.object")
-- define rule: application
rule("win.sdk.application")