From 616e2fb1b343f0a0613924edf857dde3a8c88c5f Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 00:02:53 +0300 Subject: Fil-C add toolchain --- tests/projects/c/filc/safety_test/src/main.c | 19 ++++++ tests/projects/c/filc/safety_test/test.lua | 46 ++++++++++++++ tests/projects/c/filc/safety_test/xmake.lua | 9 +++ xmake/modules/core/tools/filcc.lua | 21 +++++++ xmake/modules/detect/tools/find_filcc.lua | 41 ++++++++++++ xmake/toolchains/filc/xmake.lua | 94 ++++++++++++++++++++++++++++ 6 files changed, 230 insertions(+) create mode 100644 tests/projects/c/filc/safety_test/src/main.c create mode 100644 tests/projects/c/filc/safety_test/test.lua create mode 100644 tests/projects/c/filc/safety_test/xmake.lua create mode 100644 xmake/modules/core/tools/filcc.lua create mode 100644 xmake/modules/detect/tools/find_filcc.lua create mode 100644 xmake/toolchains/filc/xmake.lua diff --git a/tests/projects/c/filc/safety_test/src/main.c b/tests/projects/c/filc/safety_test/src/main.c new file mode 100644 index 000000000..4f5ad91b9 --- /dev/null +++ b/tests/projects/c/filc/safety_test/src/main.c @@ -0,0 +1,19 @@ +/* Test that filc catches calling a function pointer with a wrong address. + * + * Expected runtime output (exit non-zero): + * filc safety error: cannot access pointer as function with ptr != aux ... + * filc panic: thwarted a futile attempt to violate memory safety. + */ +#include +#include + +static void foo(void) +{ +} + +int main() +{ + void (*my_foo)(void) = (void(*)(void))((char*)foo + 42); + my_foo(); + return 0; +} diff --git a/tests/projects/c/filc/safety_test/test.lua b/tests/projects/c/filc/safety_test/test.lua new file mode 100644 index 000000000..34d462e7b --- /dev/null +++ b/tests/projects/c/filc/safety_test/test.lua @@ -0,0 +1,46 @@ +import("lib.detect.find_tool") +import("utils.ci.is_running", {alias = "ci_is_running"}) + +function main(t) + -- filc only supports Linux x86_64 + if os.host() ~= "linux" or os.arch() ~= "x86_64" then + return t:skip("filc is only supported on linux/x86_64") + end + + local filcc = find_tool("filcc") + if not filcc then + return t:skip("filcc not found, please install the filc package first") + end + + -- build the safety test + local flags = ci_is_running() and "-vD" or "" + os.exec("xmake f -c -y " .. flags) + os.exec("xmake -r " .. flags) + + -- find the compiled binary + local binfile = path.join("build", os.host(), os.arch(), "release", "safety_test") + assert(os.isfile(binfile), "binary not found: " .. binfile) + + -- run the binary — it MUST exit non-zero and emit a filc safety error + -- os.iorunv raises on non-zero exit in the sandbox, so catch the failure + local filc_output = nil + try + { + function () + os.iorunv(binfile, {}) + end, + catch + { + function (errors) + filc_output = tostring(errors) + end + } + } + assert(filc_output, "expected safety_test to exit non-zero, but it succeeded") + assert(filc_output:find("filc safety error", 1, true), + "expected 'filc safety error' in output, got:\n" .. filc_output) + assert(filc_output:find("filc panic", 1, true), + "expected 'filc panic' in output, got:\n" .. filc_output) + + cprint("${green}filc safety check triggered as expected${reset}") +end diff --git a/tests/projects/c/filc/safety_test/xmake.lua b/tests/projects/c/filc/safety_test/xmake.lua new file mode 100644 index 000000000..e2d47da57 --- /dev/null +++ b/tests/projects/c/filc/safety_test/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +add_requires("filc") + +target("safety_test") + set_kind("binary") + set_toolchains("filc", {packages = "filc"}) + add_packages("filc") + add_files("src/*.c") diff --git a/xmake/modules/core/tools/filcc.lua b/xmake/modules/core/tools/filcc.lua new file mode 100644 index 000000000..28aefc34a --- /dev/null +++ b/xmake/modules/core/tools/filcc.lua @@ -0,0 +1,21 @@ +--!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. +-- +-- @file filcc.lua +-- + +-- filcc is Fil-C's clang-based C compiler - inherit clang driver behaviour +inherit("clang") diff --git a/xmake/modules/detect/tools/find_filcc.lua b/xmake/modules/detect/tools/find_filcc.lua new file mode 100644 index 000000000..2f6c96fcc --- /dev/null +++ b/xmake/modules/detect/tools/find_filcc.lua @@ -0,0 +1,41 @@ +--!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. +-- +-- @file find_filcc.lua +-- + +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find filcc (Fil-C memory-safe C compiler, clang-based) +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +function main(opt) + opt = opt or {} + opt.check = opt.check or "--version" + opt.command = opt.command or "--version" + + local program = find_program(opt.program or "filcc", opt) + + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/toolchains/filc/xmake.lua b/xmake/toolchains/filc/xmake.lua new file mode 100644 index 000000000..e540aaab3 --- /dev/null +++ b/xmake/toolchains/filc/xmake.lua @@ -0,0 +1,94 @@ +--!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. +-- +-- @file xmake.lua +-- + +toolchain("filc") + set_kind("standalone") + set_homepage("https://fil-c.org/") + set_description("A memory safe implementation of the C and C++ programming languages.") + + on_check(function (toolchain) + import("lib.detect.find_tool") + + -- look in package installdir/build/bin first, then bindir/sdkdir, then PATH + local paths = {} + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir then + table.insert(paths, path.join(installdir, "build", "bin")) + end + end + local bindir = toolchain:bindir() + if bindir then + table.insert(paths, bindir) + end + local sdkdir = toolchain:sdkdir() + if sdkdir then + table.insert(paths, path.join(sdkdir, "build", "bin")) + table.insert(paths, path.join(sdkdir, "bin")) + end + + local filcc = find_tool("filcc", {paths = paths, force = true}) + if filcc then + toolchain:config_set("filcc", filcc.program) + if os.isfile(filcc.program) then + toolchain:config_set("bindir", path.directory(filcc.program)) + end + return true + end + end) + + on_load(function (toolchain) + local filcc = toolchain:config("filcc") or "filcc" + + -- filcc is the compiler and linker; ar uses the system archiver + toolchain:set("toolset", "cc", filcc) + toolchain:set("toolset", "ld", filcc) + toolchain:set("toolset", "sh", filcc) + toolchain:set("toolset", "ar", "ar") + toolchain:set("toolset", "as", filcc) + + -- add runtime include/lib dirs from the installed package + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir then + local pizfix = path.join(installdir, "pizfix") + -- stdfil.h lives in pizfix/stdfil-include/ + toolchain:add("sysincludedirs", path.join(pizfix, "stdfil-include")) + -- standard C headers (musl-based) live in pizfix/include/ + toolchain:add("sysincludedirs", path.join(pizfix, "include")) + toolchain:add("linkdirs", path.join(pizfix, "lib")) + toolchain:add("linkdirs", path.join(pizfix, "lib64")) + end + end + local sdkdir = toolchain:sdkdir() + if sdkdir and os.isdir(sdkdir) then + local pizfix = path.join(sdkdir, "pizfix") + for _, d in ipairs({"stdfil-include", "include"}) do + local includedir = path.join(pizfix, d) + if os.isdir(includedir) then + toolchain:add("sysincludedirs", includedir) + end + end + for _, libdir in ipairs({path.join(pizfix, "lib64"), path.join(pizfix, "lib")}) do + if os.isdir(libdir) then + toolchain:add("linkdirs", libdir) + end + end + end + end) -- cgit v1.3.1 From c9ceb0483382a858e17f90cc4bbcf4833cedf6cd Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 00:15:45 +0300 Subject: improve toolchain path handling and add checks for include and library directories --- xmake/toolchains/filc/xmake.lua | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/xmake/toolchains/filc/xmake.lua b/xmake/toolchains/filc/xmake.lua index e540aaab3..465183b56 100644 --- a/xmake/toolchains/filc/xmake.lua +++ b/xmake/toolchains/filc/xmake.lua @@ -25,12 +25,13 @@ toolchain("filc") on_check(function (toolchain) import("lib.detect.find_tool") - -- look in package installdir/build/bin first, then bindir/sdkdir, then PATH + -- look in package installdir/build/bin and bin first, then bindir/sdkdir, then PATH local paths = {} for _, package in ipairs(toolchain:packages()) do local installdir = package:installdir() if installdir then table.insert(paths, path.join(installdir, "build", "bin")) + table.insert(paths, path.join(installdir, "bin")) end end local bindir = toolchain:bindir() @@ -55,9 +56,12 @@ toolchain("filc") on_load(function (toolchain) local filcc = toolchain:config("filcc") or "filcc" + local bindir = toolchain:config("bindir") + local filpp = bindir and path.join(bindir, "fil++") or "fil++" - -- filcc is the compiler and linker; ar uses the system archiver + -- filcc/fil++ are the compilers and linker; ar uses the system archiver toolchain:set("toolset", "cc", filcc) + toolchain:set("toolset", "cxx", filpp) toolchain:set("toolset", "ld", filcc) toolchain:set("toolset", "sh", filcc) toolchain:set("toolset", "ar", "ar") @@ -68,12 +72,17 @@ toolchain("filc") local installdir = package:installdir() if installdir then local pizfix = path.join(installdir, "pizfix") - -- stdfil.h lives in pizfix/stdfil-include/ - toolchain:add("sysincludedirs", path.join(pizfix, "stdfil-include")) - -- standard C headers (musl-based) live in pizfix/include/ - toolchain:add("sysincludedirs", path.join(pizfix, "include")) - toolchain:add("linkdirs", path.join(pizfix, "lib")) - toolchain:add("linkdirs", path.join(pizfix, "lib64")) + for _, d in ipairs({"stdfil-include", "include"}) do + local includedir = path.join(pizfix, d) + if os.isdir(includedir) then + toolchain:add("sysincludedirs", includedir) + end + end + for _, libdir in ipairs({path.join(pizfix, "lib64"), path.join(pizfix, "lib")}) do + if os.isdir(libdir) then + toolchain:add("linkdirs", libdir) + end + end end end local sdkdir = toolchain:sdkdir() -- cgit v1.3.1 From 75e1604e1fd44459a6169b1fcb8c1fd06599feef Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 00:19:12 +0300 Subject: refactor safety test to remove dependency on find_tool and streamline package installation --- tests/projects/c/filc/safety_test/test.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/projects/c/filc/safety_test/test.lua b/tests/projects/c/filc/safety_test/test.lua index 34d462e7b..2a372b3cd 100644 --- a/tests/projects/c/filc/safety_test/test.lua +++ b/tests/projects/c/filc/safety_test/test.lua @@ -1,4 +1,3 @@ -import("lib.detect.find_tool") import("utils.ci.is_running", {alias = "ci_is_running"}) function main(t) @@ -7,14 +6,21 @@ function main(t) return t:skip("filc is only supported on linux/x86_64") end - local filcc = find_tool("filcc") - if not filcc then - return t:skip("filcc not found, please install the filc package first") + local flags = ci_is_running() and "-vD" or "" + + -- configure and install the filc package; skip if unavailable + local configured = try + { + function () + os.exec("xmake f -c -y " .. flags) + return true + end, + catch { function () end } + } + if not configured then + return t:skip("filc package not available or install failed") end - -- build the safety test - local flags = ci_is_running() and "-vD" or "" - os.exec("xmake f -c -y " .. flags) os.exec("xmake -r " .. flags) -- find the compiled binary -- cgit v1.3.1 From 6146edfaeb30011c571884987b9ee761d8abae2b Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 00:33:20 +0300 Subject: add filxx toolchain and find_filxx detection script for Fil-C C++ compiler --- xmake/modules/core/tools/filxx.lua | 21 ++++++++++++++++ xmake/modules/detect/tools/find_filxx.lua | 41 +++++++++++++++++++++++++++++++ xmake/toolchains/filc/xmake.lua | 27 ++++++++++++-------- 3 files changed, 79 insertions(+), 10 deletions(-) create mode 100644 xmake/modules/core/tools/filxx.lua create mode 100644 xmake/modules/detect/tools/find_filxx.lua diff --git a/xmake/modules/core/tools/filxx.lua b/xmake/modules/core/tools/filxx.lua new file mode 100644 index 000000000..10898fa48 --- /dev/null +++ b/xmake/modules/core/tools/filxx.lua @@ -0,0 +1,21 @@ +--!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. +-- +-- @file filxx.lua +-- + +-- fil++ is Fil-C's clang-based C++ compiler - inherit clang driver behaviour +inherit("clang") diff --git a/xmake/modules/detect/tools/find_filxx.lua b/xmake/modules/detect/tools/find_filxx.lua new file mode 100644 index 000000000..b7aa65cc9 --- /dev/null +++ b/xmake/modules/detect/tools/find_filxx.lua @@ -0,0 +1,41 @@ +--!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. +-- +-- @file find_filxx.lua +-- + +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find fil++ (Fil-C memory-safe C++ compiler, clang-based) +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +function main(opt) + opt = opt or {} + opt.check = opt.check or "--version" + opt.command = opt.command or "--version" + + local program = find_program(opt.program or "fil++", opt) + + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/toolchains/filc/xmake.lua b/xmake/toolchains/filc/xmake.lua index 465183b56..8e13f6e04 100644 --- a/xmake/toolchains/filc/xmake.lua +++ b/xmake/toolchains/filc/xmake.lua @@ -67,16 +67,25 @@ toolchain("filc") toolchain:set("toolset", "ar", "ar") toolchain:set("toolset", "as", filcc) + -- expose host system headers (GL, X11, etc.) via -idirafter so they are + -- searched AFTER filc's own libc++ headers, preventing stdlib.h conflicts + for _, sysdir in ipairs({"/usr/include", "/usr/local/include"}) do + if os.isdir(sysdir) then + toolchain:add("cflags", "-idirafter " .. sysdir) + toolchain:add("cxflags", "-idirafter " .. sysdir) + end + end + -- add runtime include/lib dirs from the installed package for _, package in ipairs(toolchain:packages()) do local installdir = package:installdir() if installdir then local pizfix = path.join(installdir, "pizfix") - for _, d in ipairs({"stdfil-include", "include"}) do - local includedir = path.join(pizfix, d) - if os.isdir(includedir) then - toolchain:add("sysincludedirs", includedir) - end + -- only add stdfil-include for stdfil.h; pizfix/include (musl C headers) + -- must NOT be added as -isystem or it breaks libc++'s stdlib.h include order + local stdfil_include = path.join(pizfix, "stdfil-include") + if os.isdir(stdfil_include) then + toolchain:add("sysincludedirs", stdfil_include) end for _, libdir in ipairs({path.join(pizfix, "lib64"), path.join(pizfix, "lib")}) do if os.isdir(libdir) then @@ -88,11 +97,9 @@ toolchain("filc") local sdkdir = toolchain:sdkdir() if sdkdir and os.isdir(sdkdir) then local pizfix = path.join(sdkdir, "pizfix") - for _, d in ipairs({"stdfil-include", "include"}) do - local includedir = path.join(pizfix, d) - if os.isdir(includedir) then - toolchain:add("sysincludedirs", includedir) - end + local stdfil_include = path.join(pizfix, "stdfil-include") + if os.isdir(stdfil_include) then + toolchain:add("sysincludedirs", stdfil_include) end for _, libdir in ipairs({path.join(pizfix, "lib64"), path.join(pizfix, "lib")}) do if os.isdir(libdir) then -- cgit v1.3.1 From 74dbb8e44c4258c491a362dcd4b0583ba1806fd5 Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 00:45:27 +0300 Subject: enhance filc toolchain: explicitly discover fil++ and streamline include/lib directory handling --- xmake/toolchains/filc/xmake.lua | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/xmake/toolchains/filc/xmake.lua b/xmake/toolchains/filc/xmake.lua index 8e13f6e04..5c7dab2d6 100644 --- a/xmake/toolchains/filc/xmake.lua +++ b/xmake/toolchains/filc/xmake.lua @@ -50,14 +50,21 @@ toolchain("filc") if os.isfile(filcc.program) then toolchain:config_set("bindir", path.directory(filcc.program)) end + -- discover fil++ explicitly rather than inferring from filcc's bindir + local filxx = find_tool("fil++", {paths = paths, force = true}) + if filxx then + toolchain:config_set("filxx", filxx.program) + end return true end end) on_load(function (toolchain) local filcc = toolchain:config("filcc") or "filcc" - local bindir = toolchain:config("bindir") - local filpp = bindir and path.join(bindir, "fil++") or "fil++" + local filpp = toolchain:config("filxx") or (function() + local bindir = toolchain:config("bindir") + return bindir and path.join(bindir, "fil++") or "fil++" + end)() -- filcc/fil++ are the compilers and linker; ar uses the system archiver toolchain:set("toolset", "cc", filcc) @@ -71,32 +78,16 @@ toolchain("filc") -- searched AFTER filc's own libc++ headers, preventing stdlib.h conflicts for _, sysdir in ipairs({"/usr/include", "/usr/local/include"}) do if os.isdir(sysdir) then - toolchain:add("cflags", "-idirafter " .. sysdir) - toolchain:add("cxflags", "-idirafter " .. sysdir) + toolchain:add("cflags", "-idirafter", sysdir) + toolchain:add("cxflags", "-idirafter", sysdir) end end - -- add runtime include/lib dirs from the installed package - for _, package in ipairs(toolchain:packages()) do - local installdir = package:installdir() - if installdir then - local pizfix = path.join(installdir, "pizfix") - -- only add stdfil-include for stdfil.h; pizfix/include (musl C headers) - -- must NOT be added as -isystem or it breaks libc++'s stdlib.h include order - local stdfil_include = path.join(pizfix, "stdfil-include") - if os.isdir(stdfil_include) then - toolchain:add("sysincludedirs", stdfil_include) - end - for _, libdir in ipairs({path.join(pizfix, "lib64"), path.join(pizfix, "lib")}) do - if os.isdir(libdir) then - toolchain:add("linkdirs", libdir) - end - end - end - end - local sdkdir = toolchain:sdkdir() - if sdkdir and os.isdir(sdkdir) then - local pizfix = path.join(sdkdir, "pizfix") + -- add runtime include/lib dirs from the installed package or sdk + local function _add_pizfix(dir) + local pizfix = path.join(dir, "pizfix") + -- only add stdfil-include for stdfil.h; pizfix/include (musl C headers) + -- must NOT be added as -isystem or it breaks libc++'s stdlib.h include order local stdfil_include = path.join(pizfix, "stdfil-include") if os.isdir(stdfil_include) then toolchain:add("sysincludedirs", stdfil_include) @@ -107,4 +98,14 @@ toolchain("filc") end end end + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir then + _add_pizfix(installdir) + end + end + local sdkdir = toolchain:sdkdir() + if sdkdir and os.isdir(sdkdir) then + _add_pizfix(sdkdir) + end end) -- cgit v1.3.1 From 03761ed3cde38efa84bd7f170415ad83bf9d2787 Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 12:05:55 +0300 Subject: refactor safety test and toolchain configuration for filc: streamline function pointer test and enhance toolset definitions --- tests/projects/c/filc/safety_test/src/main.c | 6 ++-- tests/projects/c/filc/safety_test/xmake.lua | 2 +- xmake/toolchains/filc/xmake.lua | 45 +++++++++++----------------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/tests/projects/c/filc/safety_test/src/main.c b/tests/projects/c/filc/safety_test/src/main.c index 4f5ad91b9..d23718c3e 100644 --- a/tests/projects/c/filc/safety_test/src/main.c +++ b/tests/projects/c/filc/safety_test/src/main.c @@ -7,12 +7,10 @@ #include #include -static void foo(void) -{ +static void foo(void) { } -int main() -{ +int main() { void (*my_foo)(void) = (void(*)(void))((char*)foo + 42); my_foo(); return 0; diff --git a/tests/projects/c/filc/safety_test/xmake.lua b/tests/projects/c/filc/safety_test/xmake.lua index e2d47da57..4ebbf9792 100644 --- a/tests/projects/c/filc/safety_test/xmake.lua +++ b/tests/projects/c/filc/safety_test/xmake.lua @@ -4,6 +4,6 @@ add_requires("filc") target("safety_test") set_kind("binary") - set_toolchains("filc", {packages = "filc"}) + set_toolchains("@filc") add_packages("filc") add_files("src/*.c") diff --git a/xmake/toolchains/filc/xmake.lua b/xmake/toolchains/filc/xmake.lua index 5c7dab2d6..326d50022 100644 --- a/xmake/toolchains/filc/xmake.lua +++ b/xmake/toolchains/filc/xmake.lua @@ -22,6 +22,13 @@ toolchain("filc") set_homepage("https://fil-c.org/") set_description("A memory safe implementation of the C and C++ programming languages.") + set_toolset("cc", "filcc") + set_toolset("cxx", "fil++") + set_toolset("ld", "filcc") + set_toolset("sh", "filcc") + set_toolset("ar", "ar") + set_toolset("as", "filcc") + on_check(function (toolchain) import("lib.detect.find_tool") @@ -46,40 +53,28 @@ toolchain("filc") local filcc = find_tool("filcc", {paths = paths, force = true}) if filcc then - toolchain:config_set("filcc", filcc.program) if os.isfile(filcc.program) then toolchain:config_set("bindir", path.directory(filcc.program)) - end - -- discover fil++ explicitly rather than inferring from filcc's bindir - local filxx = find_tool("fil++", {paths = paths, force = true}) - if filxx then - toolchain:config_set("filxx", filxx.program) + -- set sdkdir to the package install root so on_load can find pizfix + for _, package in ipairs(toolchain:packages()) do + local installdir = package:installdir() + if installdir and filcc.program:startswith(installdir) then + toolchain:config_set("sdkdir", installdir) + break + end + end end return true end end) on_load(function (toolchain) - local filcc = toolchain:config("filcc") or "filcc" - local filpp = toolchain:config("filxx") or (function() - local bindir = toolchain:config("bindir") - return bindir and path.join(bindir, "fil++") or "fil++" - end)() - - -- filcc/fil++ are the compilers and linker; ar uses the system archiver - toolchain:set("toolset", "cc", filcc) - toolchain:set("toolset", "cxx", filpp) - toolchain:set("toolset", "ld", filcc) - toolchain:set("toolset", "sh", filcc) - toolchain:set("toolset", "ar", "ar") - toolchain:set("toolset", "as", filcc) - -- expose host system headers (GL, X11, etc.) via -idirafter so they are -- searched AFTER filc's own libc++ headers, preventing stdlib.h conflicts for _, sysdir in ipairs({"/usr/include", "/usr/local/include"}) do if os.isdir(sysdir) then - toolchain:add("cflags", "-idirafter", sysdir) - toolchain:add("cxflags", "-idirafter", sysdir) + toolchain:add("cflags", "-idirafter " .. sysdir) + toolchain:add("cxflags", "-idirafter " .. sysdir) end end @@ -98,12 +93,6 @@ toolchain("filc") end end end - for _, package in ipairs(toolchain:packages()) do - local installdir = package:installdir() - if installdir then - _add_pizfix(installdir) - end - end local sdkdir = toolchain:sdkdir() if sdkdir and os.isdir(sdkdir) then _add_pizfix(sdkdir) -- cgit v1.3.1 From 6e2a9173275b468c842687641247679c5f60af75 Mon Sep 17 00:00:00 2001 From: Saikari Date: Fri, 3 Apr 2026 14:15:01 +0300 Subject: add filc description to README files: include details about memory safety in C/C++ implementation --- README.md | 1 + README_zh.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index c262f2761..1d1cb87ac 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ ti-c2000 TI-CGT C2000 compiler ti-c6000 TI-CGT C6000 compiler iararm IAR ARM C/C++ Compiler kotlin-native Kotlin Native Programming Language Compiler +filc A memory safe implementation of the C and C++ programming languages (https://fil-c.org/) ``` ## Supported languages diff --git a/README_zh.md b/README_zh.md index c6618920d..b48c4d630 100644 --- a/README_zh.md +++ b/README_zh.md @@ -307,6 +307,7 @@ ti-c2000 TI-CGT C2000 compiler ti-c6000 TI-CGT C6000 compiler iararm IAR ARM C/C++ Compiler kotlin-native Kotlin Native Programming Language Compiler +filc A memory safe implementation of the C and C++ programming languages (https://fil-c.org/) ``` ## 支持语言 -- cgit v1.3.1