diff options
| author | ruki <[email protected]> | 2026-01-25 22:00:34 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-25 22:00:34 +0800 |
| commit | 6fcf5e669360703422288e26d16f47ca4cda7ade (patch) | |
| tree | 14530619ff8519f7aa90afed9aa26763a6d3917a | |
| parent | c3989a33c7644a43d4c3cc5567e4e117785bc67d (diff) | |
| parent | 998581c1cc5af94486d9f631a64e7721a3f84031 (diff) | |
Merge pull request #7260 from xmake-io/fpc
Improve fpc
| -rw-r--r-- | .github/workflows/cosmocc.yml | 4 | ||||
| -rw-r--r-- | xmake/core/tool/compiler.lua | 83 | ||||
| -rw-r--r-- | xmake/languages/pascal/load.lua | 14 | ||||
| -rw-r--r-- | xmake/languages/pascal/xmake.lua | 49 | ||||
| -rw-r--r-- | xmake/modules/core/tools/fpc.lua | 52 | ||||
| -rw-r--r-- | xmake/rules/pascal/xmake.lua | 14 |
6 files changed, 196 insertions, 20 deletions
diff --git a/.github/workflows/cosmocc.yml b/.github/workflows/cosmocc.yml index 5f4479561..4bcfa9a2c 100644 --- a/.github/workflows/cosmocc.yml +++ b/.github/workflows/cosmocc.yml @@ -55,8 +55,8 @@ jobs: RUN_PROBABILITY: ${{ vars.COSMOCC_RUN_PROBABILITY || '0.5' }} build: - needs: check - if: needs.check.outputs.should-run == 'true' + #needs: check + #if: needs.check.outputs.should-run == 'true' strategy: matrix: os: [ubuntu-latest, macos-15-intel] diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index ff8ce6a5d..dce7bf532 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -203,6 +203,73 @@ function compiler.load(sourcekind, target) return instance end +--[[ +-- build the source files (compile and link) +function compiler:build(sourcefiles, targetfile, opt) + opt = opt or {} + local target = opt.target or self:target() + if not opt.target and target then + opt = table.copy(opt) + opt.target = target + end + + -- get compile flags + local compflags = opt.compflags + if not compflags then + -- patch sourcefile to get flags of the given source file + if type(sourcefiles) == "string" then + opt.sourcefile = sourcefiles + end + compflags = self:compflags(opt) + end + + -- make flags + local flags = compflags + if target then + flags = table.join(flags, target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and target and target.targetkind then + targetkind = target:kind() + end + return sandbox.load(self:_tool().build, self:_tool(), sourcefiles, targetkind or "binary", targetfile, flags, opt) +end + +-- get the build arguments list (compile and link) +function compiler:buildargv(sourcefiles, targetfile, opt) + opt = opt or {} + local target = opt.target or self:target() + if not opt.target and target then + opt = table.copy(opt) + opt.target = target + end + + -- get compile flags + local compflags = opt.compflags + if not compflags then + -- patch sourcefile to get flags of the given source file + if type(sourcefiles) == "string" then + opt.sourcefile = sourcefiles + end + compflags = self:compflags(opt) + end + + -- make flags + local flags = compflags + if target then + flags = table.join(flags, target:linkflags()) + end + + -- get target kind + local targetkind = opt.targetkind + if not targetkind and target and target.targetkind then + targetkind = target:kind() + end + return self:_tool():buildargv(sourcefiles, targetkind or "binary", targetfile, flags, opt) +end]] + -- build the source files (compile and link) function compiler:build(sourcefiles, targetfile, opt) opt = opt or {} @@ -266,9 +333,15 @@ end -- compile the source files function compiler:compile(sourcefiles, objectfile, opt) + opt = opt or {} + --[[ + local target = opt.target or self:target() + if not opt.target and target then + opt = table.copy(opt) + opt.target = target + end]] -- get compile flags - opt = opt or {} local compflags = opt.compflags if not compflags then -- patch sourcefile to get flags of the given source file @@ -289,9 +362,13 @@ end -- get the compile arguments list function compiler:compargv(sourcefiles, objectfile, opt) - - -- init options opt = opt or {} + --[[ + local target = opt.target or self:target() + if not opt.target and target then + opt = table.copy(opt) + opt.target = target + end]] -- get compile flags local compflags = opt.compflags diff --git a/xmake/languages/pascal/load.lua b/xmake/languages/pascal/load.lua index 24cbee327..45b007272 100644 --- a/xmake/languages/pascal/load.lua +++ b/xmake/languages/pascal/load.lua @@ -30,6 +30,8 @@ function _get_apis() , "target.add_arflags" , "target.add_shflags" , "target.add_rpathdirs" -- @note do not translate path, it's usually an absolute path or contains $ORIGIN/@loader_path + , "target.add_defines" + , "target.add_undefines" -- option.add_xxx , "option.add_links" , "option.add_syslinks" @@ -38,6 +40,9 @@ function _get_apis() , "option.add_arflags" , "option.add_shflags" , "option.add_rpathdirs" + , "option.add_includedirs" + , "option.add_defines" + , "option.add_undefines" -- package.add_xxx , "package.add_links" , "package.add_syslinks" @@ -47,6 +52,9 @@ function _get_apis() , "package.add_shflags" , "package.add_rpathdirs" , "package.add_linkdirs" + , "package.add_includedirs" + , "package.add_defines" + , "package.add_undefines" -- toolchain.add_xxx , "toolchain.add_links" , "toolchain.add_syslinks" @@ -56,10 +64,14 @@ function _get_apis() , "toolchain.add_shflags" , "toolchain.add_rpathdirs" , "toolchain.add_linkdirs" + , "toolchain.add_includedirs" + , "toolchain.add_defines" + , "toolchain.add_undefines" } apis.paths = { -- target.add_xxx "target.add_linkdirs" + , "target.add_includedirs" , "target.add_frameworkdirs" -- option.add_xxx , "option.add_linkdirs" @@ -70,5 +82,3 @@ end function main() return {apis = _get_apis()} end - - diff --git a/xmake/languages/pascal/xmake.lua b/xmake/languages/pascal/xmake.lua index 0b7c2ae05..de31378af 100644 --- a/xmake/languages/pascal/xmake.lua +++ b/xmake/languages/pascal/xmake.lua @@ -32,40 +32,74 @@ language("pascal") set_nameflags { object = { - "target.symbols" + "config.includedirs" + , "config.frameworkdirs" + , "config.frameworks" + , "target.symbols" , "target.warnings" + , "target.fpmodels" , "target.optimize:check" , "target.vectorexts:check" + , "target.languages" + , "target.includedirs" + , "target.defines" + , "target.undefines" + , "target.frameworkdirs" + , "target.frameworks" + , "target.exceptions" + , "target.encodings" + , "target.forceincludes" + , "toolchain.includedirs" + , "toolchain.defines" + , "toolchain.undefines" + , "toolchain.frameworkdirs" + , "toolchain.frameworks" + , "toolchain.exceptions" + , "toolchain.languages" } , binary = { "config.linkdirs" + , "config.frameworkdirs" + , "config.frameworks" + , "config.rpathdirs" + , "config.syslinks" , "target.linkdirs" + , "target.frameworkdirs" , "target.rpathdirs" , "target.strip" , "target.symbols" + , "target.optimize:check" , "toolchain.linkdirs" , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" - , "target.frameworks" - , "target.frameworkdirs" , "toolchain.links" - , "config.syslinks" + , "target.frameworks" + , "toolchain.frameworks" , "target.syslinks" , "toolchain.syslinks" } , shared = { "config.linkdirs" + , "config.frameworkdirs" + , "config.frameworks" + , "config.rpathdirs" + , "config.syslinks" , "target.linkdirs" + , "target.frameworkdirs" + , "target.rpathdirs" , "target.strip" , "target.symbols" + , "target.optimize:check" , "toolchain.linkdirs" + , "toolchain.rpathdirs" + , "toolchain.frameworkdirs" , "config.links" , "target.links" - , "target.frameworks" - , "target.frameworkdirs" , "toolchain.links" - , "config.syslinks" + , "target.frameworks" + , "toolchain.frameworks" , "target.syslinks" , "toolchain.syslinks" } @@ -87,4 +121,3 @@ language("pascal") , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } } } - diff --git a/xmake/modules/core/tools/fpc.lua b/xmake/modules/core/tools/fpc.lua index 18298cd6c..c08fcef14 100644 --- a/xmake/modules/core/tools/fpc.lua +++ b/xmake/modules/core/tools/fpc.lua @@ -102,14 +102,56 @@ function nf_frameworkdir(self, frameworkdir) return {"-k-F", path.translate(frameworkdir)} end +-- make the includedir flag +function nf_includedir(self, includedir) + return {"-Fi" .. path.translate(includedir)} +end + +-- make the define flag +function nf_define(self, macro) + return {"-d" .. macro} +end + +-- make the undefine flag +function nf_undefine(self, macro) + return {"-u" .. macro} +end + +-- make the language flag +function nf_language(self, language) + local mode = { + pascal = "-Mfpc", + fpc = "-Mfpc", + objfpc = "-Mobjfpc", + delphi = "-Mdelphi", + macpas = "-Mmacpas", + isopas = "-Miso", + extendedpascal = "-Mextendedpascal", + delphiunicode = "-Mdelphiunicode", + } + return mode[language:lower()] +end + +-- make the exception flag +-- considering this applies to all dialects, +-- make this only accept on/off +function nf_exception(self, exp) + return {exp == "off" and "-Sx-" or "-Sx"} +end + -- make the build arguments list -function buildargv(self, sourcefiles, targetkind, targetfile, flags) - return self:program(), table.join(flags, "-o" .. targetfile, sourcefiles) +function buildargv(self, sourcefiles, targetkind, targetfile, flags, opt) + opt = opt or {} + local extraflags = {} + local objectdir = opt.target and opt.target:objectdir() + if objectdir then + table.insert(extraflags, "-FU" .. path.translate(objectdir)) + end + return self:program(), table.join(flags, extraflags, "-o" .. targetfile, sourcefiles) end -- build the target file -function build(self, sourcefiles, targetkind, targetfile, flags) +function build(self, sourcefiles, targetkind, targetfile, flags, opt) os.mkdir(path.directory(targetfile)) - os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags)) + os.runv(buildargv(self, sourcefiles, targetkind, targetfile, flags, opt)) end - diff --git a/xmake/rules/pascal/xmake.lua b/xmake/rules/pascal/xmake.lua index 4b318702b..03b027e07 100644 --- a/xmake/rules/pascal/xmake.lua +++ b/xmake/rules/pascal/xmake.lua @@ -31,3 +31,17 @@ rule("pascal") -- inherit links and linkdirs of all dependent targets by default add_deps("utils.inherit.links") + + -- support `add_files("src/*.o")` and `add_files("src/*.a")` to merge object and archive files to target + add_deps("utils.merge.object", "utils.merge.archive") + + -- we attempt to extract symbols to the independent file and + -- strip self-target binary if `set_symbols("debug")` and `set_strip("all")` are enabled + add_deps("utils.symbols.extract") + + -- add platform rules + add_deps("platform.wasm") + add_deps("platform.windows") + + -- add linker rules + add_deps("linker") |
