diff options
| author | ruki <[email protected]> | 2025-12-02 16:16:13 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-02 16:16:13 +0800 |
| commit | bc7caf95a9cfdefed930937e8450997a4cdc8191 (patch) | |
| tree | de6f77256d55a0f49c5889b10b3962a6406673a8 | |
| parent | f4533a6c109732c983329d5121929b9635409a3d (diff) | |
| parent | 73e234824c235191f430400f4bb7b39421ee1fb4 (diff) | |
Merge pull request #7088 from xmake-io/rule
Improve c++/objc rules
| -rw-r--r-- | .github/workflows/solaris.yml | 18 | ||||
| -rw-r--r-- | xmake/rules/c++/config/basic.lua | 38 | ||||
| -rw-r--r-- | xmake/rules/c++/config/main.lua (renamed from xmake/rules/c++/build_optimization/xmake.lua) | 28 | ||||
| -rw-r--r-- | xmake/rules/c++/config/optimization.lua (renamed from xmake/rules/c++/build_optimization/config.lua) | 26 | ||||
| -rw-r--r-- | xmake/rules/c++/config/sanitizer.lua (renamed from xmake/rules/c++/build_sanitizer/config.lua) | 5 | ||||
| -rw-r--r-- | xmake/rules/c++/xmake.lua | 24 | ||||
| -rw-r--r-- | xmake/rules/objc++/config/basic.lua | 36 | ||||
| -rw-r--r-- | xmake/rules/objc++/config/main.lua (renamed from xmake/rules/c++/build_sanitizer/xmake.lua) | 35 | ||||
| -rw-r--r-- | xmake/rules/objc++/xmake.lua | 24 |
9 files changed, 151 insertions, 83 deletions
diff --git a/.github/workflows/solaris.yml b/.github/workflows/solaris.yml index 9e044b036..6f4dbba76 100644 --- a/.github/workflows/solaris.yml +++ b/.github/workflows/solaris.yml @@ -19,17 +19,17 @@ jobs: script: | const fs = require('fs'); const outputFile = process.env.GITHUB_OUTPUT; - + // Always run for release events if (context.eventName === 'release') { fs.appendFileSync(outputFile, `should-run=true\n`); core.info('Release event detected. Will run tests.'); return; } - + // Execution probability (default 50%, can be overridden via env) const probability = parseFloat(process.env.RUN_PROBABILITY || '0.5'); - + // Generate deterministic "random" number based on commit SHA, run ID, and current time // Adding time ensures better randomness while keeping same commit/run consistent const timeSeed = Math.floor(Date.now() / (1000 * 60 * 60)); // Round to hour for consistency @@ -43,7 +43,7 @@ jobs: // Normalize to 0-1 range const random = Math.abs(hash) / 2147483647; const shouldRun = random < probability; - + // Use environment file instead of deprecated set-output fs.appendFileSync(outputFile, `should-run=${shouldRun}\n`); if (shouldRun) { @@ -72,7 +72,15 @@ jobs: with: usesh: true prepare: | - pkgutil -y -i socat git gmake bash gcc4g++ || pkgutil -y -i socat git gmake bash gcc5g++ || pkg install -y developer/gcc || true + # Try OpenCSW first (for older Solaris) + if command -v pkgutil >/dev/null 2>&1; then + pkgutil -U || true + pkgutil -y -i socat git gmake bash gcc4g++ 2>/dev/null || pkgutil -y -i socat git gmake bash gcc5g++ 2>/dev/null || true + fi + # Try IPS (for newer Solaris) + if command -v pkg >/dev/null 2>&1; then + pkg install --accept developer/gcc developer/build/gnu-make developer/versioning/git || true + fi run: | cd $GITHUB_WORKSPACE bash ./configure diff --git a/xmake/rules/c++/config/basic.lua b/xmake/rules/c++/config/basic.lua new file mode 100644 index 000000000..e9c810417 --- /dev/null +++ b/xmake/rules/c++/config/basic.lua @@ -0,0 +1,38 @@ +--!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-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file basic.lua +-- + +-- main entry +function main(target, sourcekind) + -- enable c++ exceptions by default on Windows + if sourcekind == "cxx" and target:is_plat("windows") and not target:get("exceptions") then + target:set("exceptions", "cxx") + end + + -- https://github.com/xmake-io/xmake/issues/4621 + -- tcc on Windows static library needs special handling + if target:is_plat("windows") and target:is_static() then + local toolname = sourcekind == "cxx" and "cxx" or "cc" + if target:has_tool(toolname, "tcc") then + target:set("extension", ".a") + target:set("prefixname", "lib") + end + end +end + diff --git a/xmake/rules/c++/build_optimization/xmake.lua b/xmake/rules/c++/config/main.lua index 82693035e..78d1362af 100644 --- a/xmake/rules/c++/build_optimization/xmake.lua +++ b/xmake/rules/c++/config/main.lua @@ -15,18 +15,24 @@ -- Copyright (C) 2015-present, Xmake Open Source Community. -- -- @author ruki --- @file xmake.lua +-- @file main.lua -- --- define rule: c.build.optimization -rule("c.build.optimization") - on_config(function (target) - import("config")(target, "cc") - end) +-- imports +import("basic", {alias = "config_basic"}) +import("optimization", {alias = "config_optimization"}) +import("sanitizer", {alias = "config_sanitizer"}) --- define rule: c++.build.optimization -rule("c++.build.optimization") - on_config(function (target) - import("config")(target, "cxx") - end) +-- main entry +function main(target, sourcekind) + + -- config basic configs + config_basic(target, sourcekind) + + -- config optimization configs + config_optimization(target, sourcekind) + + -- config sanitizer configs + config_sanitizer(target, sourcekind) +end diff --git a/xmake/rules/c++/build_optimization/config.lua b/xmake/rules/c++/config/optimization.lua index 686ef76c5..4332bd833 100644 --- a/xmake/rules/c++/build_optimization/config.lua +++ b/xmake/rules/c++/config/optimization.lua @@ -15,7 +15,7 @@ -- Copyright (C) 2015-present, Xmake Open Source Community. -- -- @author ruki --- @file config.lua +-- @file optimization.lua -- -- imports @@ -24,10 +24,15 @@ import("core.project.project") -- add lto optimization function _add_lto_optimization(target, sourcekind) - -- add cflags local _, cc = target:tool(sourcekind) - local cflag = sourcekind == "cxx" and "cxxflags" or "cflags" + local flagnames = { + cc = "cflags", + cxx = "cxxflags", + mm = "mflags", + mxx = "mxxflags" + } + local cflag = flagnames[sourcekind] or (sourcekind == "cxx" and "cxxflags" or "cflags") if cc == "cl" then target:add(cflag, "-GL") elseif cc == "clang" or cc == "clangxx" or cc == "clang_cl" then @@ -67,7 +72,14 @@ function _add_lto_optimization(target, sourcekind) -- @see https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html local optimize = target:get("optimize") if optimize then - local optimize_flags = compiler.map_flags(sourcekind == "cc" and "c" or "cxx", "optimize", optimize) + local lang_map = { + cc = "c", + cxx = "cxx", + mm = "c", + mxx = "cxx" + } + local lang = lang_map[sourcekind] or "cxx" + local optimize_flags = compiler.map_flags(lang, "optimize", optimize) target:add("ldflags", optimize_flags) target:add("shflags", optimize_flags) end @@ -87,9 +99,11 @@ function _add_lto_optimization(target, sourcekind) end end +-- main entry function main(target, sourcekind) - if target:policy("build.optimization.lto") or - project.policy("build.optimization.lto") then + -- handle lto optimization + if target:policy("build.optimization.lto") or project.policy("build.optimization.lto") then _add_lto_optimization(target, sourcekind) end end + diff --git a/xmake/rules/c++/build_sanitizer/config.lua b/xmake/rules/c++/config/sanitizer.lua index be5ba7225..aeea8492f 100644 --- a/xmake/rules/c++/build_sanitizer/config.lua +++ b/xmake/rules/c++/config/sanitizer.lua @@ -15,18 +15,16 @@ -- Copyright (C) 2015-present, Xmake Open Source Community. -- -- @author ruki --- @file config.lua +-- @file sanitizer.lua -- -- imports -import("core.tool.compiler") import("core.project.project") import("lib.detect.find_tool") import("core.base.semver") -- add build sanitizer function _add_build_sanitizer(target, sourcekind, checkmode) - -- add cflags local _, cc = target:tool(sourcekind) local flagnames = { @@ -62,7 +60,6 @@ function main(target, sourcekind) end if sanitizer then - -- enable the debug symbols for sanitizer if not target:get("symbols") then target:set("symbols", "debug") diff --git a/xmake/rules/c++/xmake.lua b/xmake/rules/c++/xmake.lua index e0673837d..dbb24451d 100644 --- a/xmake/rules/c++/xmake.lua +++ b/xmake/rules/c++/xmake.lua @@ -20,31 +20,19 @@ rule("c.build") set_sourcekinds("cc") - add_deps("c.build.pcheader", "c.build.optimization", "c.build.sanitizer") - on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) + add_deps("c.build.pcheader") on_config(function (target) - -- https://github.com/xmake-io/xmake/issues/4621 - if target:is_plat("windows") and target:is_static() and target:has_tool("cc", "tcc") then - target:set("extension", ".a") - target:set("prefixname", "lib") - end + import("config")(target, "cc") end) + on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) rule("c++.build") set_sourcekinds("cxx") - add_deps("c++.build.pcheader", "c++.build.modules", "c++.build.optimization", "c++.build.sanitizer") - on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) + add_deps("c++.build.pcheader", "c++.build.modules") on_config(function (target) - -- enable c++ exceptions by default - if target:is_plat("windows") and not target:get("exceptions") then - target:set("exceptions", "cxx") - end - -- https://github.com/xmake-io/xmake/issues/4621 - if target:is_plat("windows") and target:is_static() and target:has_tool("cxx", "tcc") then - target:set("extension", ".a") - target:set("prefixname", "lib") - end + import("config")(target, "cxx") end) + on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) rule("c") diff --git a/xmake/rules/objc++/config/basic.lua b/xmake/rules/objc++/config/basic.lua new file mode 100644 index 000000000..4da2eed43 --- /dev/null +++ b/xmake/rules/objc++/config/basic.lua @@ -0,0 +1,36 @@ +--!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-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file basic.lua +-- + +function main(target, sourcekind) + if sourcekind == "mm" or sourcekind == "mxx" then + -- deprecated, we only need to use `add_mflags("-fno-objc-arc")` or `add_mxxflags("-fno-objc-arc")` to override it + local arc_value = sourcekind == "mm" and target:values("objc.build.arc") or target:values("objc++.build.arc") + if arc_value == false then + local flag_name = sourcekind == "mm" and "mflags" or "mxxflags" + target:add(flag_name, "-fno-objc-arc") + end + + -- add frameworks for Apple platforms + if target:is_plat("macosx", "iphoneos", "watchos") then + target:add("frameworks", "Foundation", "CoreFoundation") + end + end +end + diff --git a/xmake/rules/c++/build_sanitizer/xmake.lua b/xmake/rules/objc++/config/main.lua index 89149f414..43d2b0096 100644 --- a/xmake/rules/c++/build_sanitizer/xmake.lua +++ b/xmake/rules/objc++/config/main.lua @@ -15,30 +15,23 @@ -- Copyright (C) 2015-present, Xmake Open Source Community. -- -- @author ruki --- @file xmake.lua +-- @file main.lua -- --- define rule: c.build.sanitizer -rule("c.build.sanitizer") - on_config(function (target) - import("config")(target, "cc") - end) +-- imports +import("rules.objc++.config.basic", {rootdir = os.programdir(), alias = "config_basic"}) +import("rules.c++.config.optimization", {rootdir = os.programdir(), alias = "config_optimization"}) +import("rules.c++.config.sanitizer", {rootdir = os.programdir(), alias = "config_sanitizer"}) --- define rule: c++.build.sanitizer -rule("c++.build.sanitizer") - on_config(function (target) - import("config")(target, "cxx") - end) +-- main entry +function main(target, sourcekind) + -- handle objc++ basic configs + config_basic(target, sourcekind) --- define rule: objc.build.sanitizer -rule("objc.build.sanitizer") - on_config(function (target) - import("config")(target, "mm") - end) + -- handle optimization.lto + config_optimization(target, sourcekind) --- define rule: objc++.build.sanitizer -rule("objc++.build.sanitizer") - on_config(function (target) - import("config")(target, "mxx") - end) + -- handle sanitizer + config_sanitizer(target, sourcekind) +end diff --git a/xmake/rules/objc++/xmake.lua b/xmake/rules/objc++/xmake.lua index fe857deef..23cdc3faa 100644 --- a/xmake/rules/objc++/xmake.lua +++ b/xmake/rules/objc++/xmake.lua @@ -21,30 +21,18 @@ -- define rule: objc.build rule("objc.build") set_sourcekinds("mm") - add_deps("objc.build.pcheader", "c.build.optimization", "objc.build.sanitizer") - after_load(function (target) - -- deprecated, we only need to use `add_mflags("-fno-objc-arc")` to override it - if target:values("objc.build.arc") == false then - target:add("mflags", "-fno-objc-arc") - end - if target:is_plat("macosx", "iphoneos", "watchos") then - target:add("frameworks", "Foundation", "CoreFoundation") - end + add_deps("objc.build.pcheader") + on_config(function (target) + import("config")(target, "mm") end) on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) -- define rule: objc++.build rule("objc++.build") set_sourcekinds("mxx") - add_deps("objc++.build.pcheader", "c++.build.optimization", "objc++.build.sanitizer") - after_load(function (target) - -- deprecated, we only need to use `add_mxxflags("-fno-objc-arc")` to override it - if target:values("objc++.build.arc") == false then - target:add("mxxflags", "-fno-objc-arc") - end - if target:is_plat("macosx", "iphoneos", "watchos") then - target:add("frameworks", "Foundation", "CoreFoundation") - end + add_deps("objc++.build.pcheader") + on_config(function (target) + import("config")(target, "mxx") end) on_build_files("private.action.build.object", {jobgraph = true, batch = true, distcc = true}) |
