From af56ebfae6eac0752954884db2a7bbca7c0d4fd3 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 Jan 2025 22:28:33 +0800 Subject: [PATCH] Add Xmake --- .gitmodules | 3 + grammars.yml | 2 + lib/linguist/languages.yml | 12 ++ samples/Xmake/filenames/xmake.lua | 20 +++ samples/Xmake/sample1.xmake.lua | 47 +++++ samples/Xmake/sample2.xmake.lua | 157 +++++++++++++++++ samples/Xmake/sample3.xmake.lua | 76 ++++++++ samples/Xmake/sample4.xmake.lua | 139 +++++++++++++++ samples/Xmake/sample5.xmake.lua | 44 +++++ samples/Xmake/sample6.xmake.lua | 20 +++ samples/Xmake/sample7.xmake.lua | 162 ++++++++++++++++++ samples/Xmake/sample8.xmake.lua | 31 ++++ samples/Xmake/sample9.xmake.lua | 51 ++++++ vendor/grammars/xmake-lua.tmbundle | 1 + .../git_submodule/xmake-lua.tmbundle.dep.yml | 31 ++++ 15 files changed, 796 insertions(+) create mode 100644 samples/Xmake/filenames/xmake.lua create mode 100644 samples/Xmake/sample1.xmake.lua create mode 100644 samples/Xmake/sample2.xmake.lua create mode 100644 samples/Xmake/sample3.xmake.lua create mode 100644 samples/Xmake/sample4.xmake.lua create mode 100644 samples/Xmake/sample5.xmake.lua create mode 100644 samples/Xmake/sample6.xmake.lua create mode 100644 samples/Xmake/sample7.xmake.lua create mode 100644 samples/Xmake/sample8.xmake.lua create mode 100644 samples/Xmake/sample9.xmake.lua create mode 160000 vendor/grammars/xmake-lua.tmbundle create mode 100644 vendor/licenses/git_submodule/xmake-lua.tmbundle.dep.yml diff --git a/.gitmodules b/.gitmodules index 1612334af..ef20ba7d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1449,6 +1449,9 @@ [submodule "vendor/grammars/xc.tmbundle"] path = vendor/grammars/xc.tmbundle url = https://github.com/graymalkin/xc.tmbundle +[submodule "vendor/grammars/xmake-lua.tmbundle"] + path = vendor/grammars/xmake-lua.tmbundle + url = https://github.com/xmake-io/xmake-lua.tmbundle [submodule "vendor/grammars/xml.tmbundle"] path = vendor/grammars/xml.tmbundle url = https://github.com/textmate/xml.tmbundle diff --git a/grammars.yml b/grammars.yml index e030d65dc..6d4a40ea0 100644 --- a/grammars.yml +++ b/grammars.yml @@ -1313,6 +1313,8 @@ vendor/grammars/wollok-sublime: - source.wollok vendor/grammars/xc.tmbundle: - source.xc +vendor/grammars/xmake-lua.tmbundle: +- source.xmake vendor/grammars/xml.tmbundle: - text.xml - text.xml.xsl diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 5b9d9ef6f..b84b76a11 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -8798,3 +8798,15 @@ xBase: tm_scope: source.harbour ace_mode: text language_id: 421 +Xmake: + type: programming + color: "#22a079" + extensions: + - ".xmake" + - ".xmake.lua" + filenames: + - xmake.lua + tm_scope: source.xmake + ace_mode: text + language_id: 422 + diff --git a/samples/Xmake/filenames/xmake.lua b/samples/Xmake/filenames/xmake.lua new file mode 100644 index 000000000..cf6882d09 --- /dev/null +++ b/samples/Xmake/filenames/xmake.lua @@ -0,0 +1,20 @@ +set_project("sample") +set_version("1.0.0") + +add_rules("mode.debug", "mode.release") + +option("test", {default = false, description = "the test option"}) + +add_requires("zlib", {system = false}) + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("zlib") + if is_plat("windows") then + add_defines("WIN32") + end + if has_config("test") then + add_defines("TEST") + end + diff --git a/samples/Xmake/sample1.xmake.lua b/samples/Xmake/sample1.xmake.lua new file mode 100644 index 000000000..8fdd99b9f --- /dev/null +++ b/samples/Xmake/sample1.xmake.lua @@ -0,0 +1,47 @@ +add_rules("mode.debug", "mode.release") + +-- set cross-compliation platform +set_plat("cross") +set_arch("arm") + +-- lock requires +set_policy("package.requires_lock", true) + +-- custom toolchain +toolchain("my_muslcc") + set_homepage("https://musl.cc/") + set_description("The musl-based cross-compilation toolchains") + set_kind("cross") + on_load(function (toolchain) + toolchain:load_cross_toolchain() + if toolchain:is_arch("arm") then + toolchain:add("cxflags", "-march=armv7-a", "-msoft-float", {force = true}) + toolchain:add("ldflags", "-march=armv7-a", "-msoft-float", {force = true}) + end + toolchain:add("syslinks", "gcc", "c") + end) +toolchain_end() + +-- add library packages +-- for testing zlib/xmake, libplist/autoconf, libogg/cmake +add_requires("zlib", "libogg", {system = false}) +if is_host("macosx", "linux", "bsd") then + add_requires("libplist", {system = false}) +end + +-- add toolchains package +add_requires("muslcc") + +-- set global toolchains for target and packages +set_toolchains("my_muslcc@muslcc") + +-- use the builltin toolchain("muslcc") instead of "my_muslcc" +--set_toolchains("@muslcc") + +target("test") + set_kind("binary") + add_files("src/*.c") + add_packages("zlib", "libplist", "libogg") + if has_package("libplist") then + add_defines("HAVE_LIBPLIST") + end diff --git a/samples/Xmake/sample2.xmake.lua b/samples/Xmake/sample2.xmake.lua new file mode 100644 index 000000000..8ff6322ee --- /dev/null +++ b/samples/Xmake/sample2.xmake.lua @@ -0,0 +1,157 @@ +-- project +set_project("xmake") + +-- version +set_version("2.9.7", {build = "%Y%m%d"}) + +-- set xmake min version +set_xmakever("2.8.5") + +-- set all warnings as errors +set_warnings("all", "error") + +-- set language: c99, c++11 +set_languages("c99", "cxx11") + +-- add release and debug modes +add_rules("mode.release", "mode.debug") +if is_mode("release") then + set_optimize("smallest") + if is_plat("windows") then + add_ldflags("/LTCG") + end +end + +-- disable some compiler errors +add_cxflags("-Wno-error=deprecated-declarations", "-fno-strict-aliasing", "-Wno-error=nullability-completeness", "-Wno-error=parentheses-equality") + +-- add definitions +add_defines("_GNU_SOURCE=1", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE") + +-- add vectorexts +--[[ +if is_arch("x86", "x64", "i386", "x86_64") then + add_vectorexts("sse", "sse2", "sse3", "avx", "avx2") +elseif is_arch("arm.*") then + add_vectorexts("neon") +end]] + +-- for the windows platform (msvc) +if is_plat("windows") then + set_runtimes("MT") + add_links("kernel32", "user32", "gdi32") +end + +-- for mode coverage +if is_mode("coverage") then + add_ldflags("-coverage", "-fprofile-arcs", "-ftest-coverage") +end + +-- set cosmocc toolchain, e.g. xmake f -p linux --cosmocc=y +if has_config("cosmocc") then + add_requires("cosmocc") + set_toolchains("@cosmocc") + set_policy("build.ccache", false) +end + +-- use cosmocc toolchain +option("cosmocc", {default = false, description = "Use cosmocc toolchain to build once and run anywhere."}) + +-- embed all script files +option("embed", {default = false, description = "Embed all script files."}) + +-- the runtime option +option("runtime") + set_default("lua") + set_description("Use luajit or lua runtime") + set_values("luajit", "lua") +option_end() + +-- the lua-cjson option +option("lua_cjson") + set_default(true) + set_description("Use lua-cjson as json parser") +option_end() + +-- the readline option +option("readline") + set_description("Enable or disable readline library") + add_links("readline") + add_cincludes("stdio.h", "readline/readline.h") + add_cfuncs("readline") + add_defines("XM_CONFIG_API_HAVE_READLINE") + add_deps("cosmocc") + after_check(function (option) + if option:dep("cosmocc"):enabled() then + option:enable(false) + end + end) +option_end() + +-- the curses option +option("curses") + set_description("Enable or disable curses library") + add_defines("XM_CONFIG_API_HAVE_CURSES") + add_deps("cosmocc") + before_check(function (option) + if is_plat("mingw") then + option:add("cincludes", "ncursesw/curses.h") + option:add("links", "ncursesw") + else + option:add("cincludes", "curses.h") + option:add("links", "curses") + end + end) + after_check(function (option) + if option:dep("cosmocc"):enabled() then + option:enable(false) + end + end) +option_end() + +-- the pdcurses option +option("pdcurses") + set_default(true) + set_description("Enable or disable pdcurses library") + add_defines("PDCURSES") + add_defines("XM_CONFIG_API_HAVE_CURSES") +option_end() + +-- only build xmake libraries for development? +option("onlylib") + set_default(false) + set_description("Only build xmake libraries for development") +option_end() + +-- suppress warnings +if is_plat("windows") then + add_defines("_CRT_SECURE_NO_WARNINGS") + add_cxflags("/utf-8") +end + +-- add projects +includes("src/sv", "src/lz4", "src/xmake", "src/cli") +if namespace then + namespace("tbox", function () + includes("src/tbox") + end) +else + includes("src/tbox") +end +if has_config("lua_cjson") then + includes("src/lua-cjson") +end +if is_config("runtime", "luajit") then + includes("src/luajit") +else + includes("src/lua") +end +if is_plat("windows") then + includes("src/pdcurses") +end + +-- add xpack +includes("@builtin/xpack") +if xpack then + includes("xpack.lua") +end diff --git a/samples/Xmake/sample3.xmake.lua b/samples/Xmake/sample3.xmake.lua new file mode 100644 index 000000000..ac943fb9e --- /dev/null +++ b/samples/Xmake/sample3.xmake.lua @@ -0,0 +1,76 @@ +target("xmake") + set_kind("static") + + -- add deps + add_deps("sv", "lz4") + if namespace then + add_deps("tbox::tbox") + else + add_deps("tbox") + end + if is_config("runtime", "luajit") then + add_deps("luajit") + else + add_deps("lua") + end + if has_config("lua_cjson") then + add_deps("lua-cjson") + end + if is_plat("windows") and has_config("pdcurses") then + add_deps("pdcurses") + end + + -- add definitions + add_defines("__tb_prefix__=\"xmake\"") + if is_mode("debug") then + add_defines("__tb_debug__", {public = true}) + end + + -- set the auto-generated config.h + set_configdir("$(buildir)/$(plat)/$(arch)/$(mode)") + add_configfiles("xmake.config.h.in") + + -- add includes directory + add_includedirs("..", {interface = true}) + add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)", {public = true}) + add_includedirs("../xxhash") + add_includedirs("$(projectdir)/../xmake/scripts/module") + + -- add header files + add_headerfiles("../(xmake/*.h)") + add_headerfiles("../(xmake/prefix/*.h)") + add_headerfiles("$(buildir)/$(plat)/$(arch)/$(mode)/xmake.config.h", {prefixdir = "xmake"}) + + -- add the common source files + add_files("**.c|winos/*.c") + if is_plat("windows", "msys", "mingw", "cygwin") then + add_files("winos/*.c") + end + + -- add options + add_options("readline") + if is_plat("windows") then + add_options("pdcurses") + else + add_options("curses") + end + + -- add definitions + if is_plat("windows") then + add_defines("UNICODE", "_UNICODE") + end + + -- embed all script files + add_rules("utils.bin2c", {linewidth = 16, extensions = ".xmz"}) + on_config(function (target) + import("utils.archive.archive") + if has_config("embed") then + local archivefile = path.join(target:autogendir(), "bin2c", "xmake.xmz") + print("archiving %s ..", archivefile) + os.tryrm(archivefile) + local rootdir = path.normalize(path.join(os.projectdir(), "..", "xmake")) + archive(archivefile, rootdir, {recurse = true, curdir = rootdir}) + target:add("files", archivefile) + target:add("defines", "XM_EMBED_ENABLE=1") + end + end) diff --git a/samples/Xmake/sample4.xmake.lua b/samples/Xmake/sample4.xmake.lua new file mode 100644 index 000000000..c0c6ae880 --- /dev/null +++ b/samples/Xmake/sample4.xmake.lua @@ -0,0 +1,139 @@ +xpack("xmake") + set_homepage("https://xmake.io") + set_title("Xmake build utility ($(arch))") + set_description("A cross-platform build utility based on Lua.") + set_copyright("Copyright (C) 2015-present, TBOOX Open Source Group") + set_author("ruki ") + set_licensefile("../LICENSE.md") + set_formats("nsis", "wix", "zip") + add_targets("cli") + set_bindir(".") + set_iconfile("src/cli/xmake.ico") + + add_components("LongPath") + + on_load(function (package) + local arch = package:arch() + if package:is_plat("windows") then + if arch == "x64" then + arch = "win64" + elseif arch == "x86" then + arch = "win32" + end + end + package:set("basename", "xmake-v$(version)." .. arch) + local format = package:format() + if format == "zip" then + package:set("prefixdir", "xmake") + end + end) + + before_package(function (package) + import("net.http") + import("utils.archive") + import("core.base.global") + local format = package:format() + if package:is_plat("windows") and (format == "nsis" or format == "wix" or format == "zip") then + local winenv = path.join(os.programdir(), "winenv") + if false then -- os.isdir(winenv) then + package:add("installfiles", path.join(winenv, "**"), {rootdir = path.directory(winenv)}) + else + local arch = package:arch() + local url_7z = "https://github.com/xmake-mirror/7zip/releases/download/24.08/7z24.08-" .. arch .. ".zip" + local curl_version = "8.11.0_4" + local url_curl = "https://curl.se/windows/dl-" .. curl_version .. "/curl-" .. curl_version + if package:is_arch("x64", "x86_64") then + url_curl = url_curl .. "-win64-mingw.zip" + elseif package:is_arch("arm64") then + url_curl = url_curl .. "-win64a-mingw.zip" + else + url_curl = url_curl .. "-win32-mingw.zip" + end + local archive_7z = path.join(package:buildir(), "7z.zip") + local archive_curl = path.join(package:buildir(), "curl.zip") + local tmpdir_7z = path.join(package:buildir(), "7z") + local tmpdir_curl = path.join(package:buildir(), "curl") + local winenv_bindir = path.join(package:buildir(), "winenv", "bin") + os.mkdir(winenv_bindir) + http.download(url_7z, archive_7z, {insecure = global.get("insecure-ssl")}) + archive.extract(archive_7z, tmpdir_7z) + os.cp(path.join(tmpdir_7z, "*"), winenv_bindir) + http.download(url_curl, archive_curl, {insecure = global.get("insecure-ssl")}) + archive.extract(archive_curl, tmpdir_curl) + os.cp(path.join(tmpdir_curl, "*", "bin", "*.exe"), winenv_bindir) + os.cp(path.join(tmpdir_curl, "*", "bin", "*.crt"), winenv_bindir) + winenv = path.directory(winenv_bindir) + package:add("installfiles", path.join(winenv, "**"), {rootdir = path.directory(winenv)}) + end + end + end) + +xpack_component("LongPath") + set_title("Enable Long Path") + set_description("Increases the maximum path length limit, up to 32,767 characters (before 256).") + on_installcmd(function (component, batchcmds) + batchcmds:rawcmd("nsis", [[ + ${If} $NoAdmin == "false" + ; Enable long path + WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1 + ${EndIf}]]) + batchcmds:rawcmd("wix", [[ + + + + ]]) + end) + +xpack("xmakesrc") + set_homepage("https://xmake.io") + set_title("Xmake build utility ($(arch))") + set_description("A cross-platform build utility based on Lua.") + set_copyright("Copyright (C) 2015-present, TBOOX Open Source Group") + set_author("ruki ") + set_formats("srczip", "srctargz", "runself", "srpm", "deb") + set_basename("xmake-v$(version)") + set_prefixdir("xmake-$(version)") + set_license("Apache-2.0") + before_package(function (package) + import("devel.git") + + local rootdir = path.join(os.tmpfile(package:basename()) .. ".dir", "repo") + if not os.isdir(rootdir) then + os.tryrm(rootdir) + os.cp(path.directory(os.projectdir()), rootdir) + + git.clean({repodir = rootdir, force = true, all = true}) + git.reset({repodir = rootdir, hard = true}) + if os.isfile(path.join(rootdir, ".gitmodules")) then + git.submodule.clean({repodir = rootdir, force = true, all = true}) + git.submodule.reset({repodir = rootdir, hard = true}) + end + end + + local extraconf = {rootdir = rootdir} + package:add("sourcefiles", path.join(rootdir, "core/**|src/pdcurses/**|src/luajit/**|src/tbox/tbox/src/demo/**"), extraconf) + package:add("sourcefiles", path.join(rootdir, "xmake/**|scripts/vsxmake/**"), extraconf) + package:add("sourcefiles", path.join(rootdir, "*.md"), extraconf) + package:add("sourcefiles", path.join(rootdir, "configure"), extraconf) + package:add("sourcefiles", path.join(rootdir, "scripts/*.sh"), extraconf) + package:add("sourcefiles", path.join(rootdir, "scripts/man/**"), extraconf) + package:add("sourcefiles", path.join(rootdir, "scripts/debian/**"), extraconf) + package:add("sourcefiles", path.join(rootdir, "scripts/msys/**"), extraconf) + end) + + on_buildcmd(function (package, batchcmds) + local format = package:format() + if format == "srpm" or format == "deb" then + batchcmds:runv("./configure") + batchcmds:runv("make", {"-j4"}) + end + end) + + on_installcmd(function (package, batchcmds) + local format = package:format() + if format == "runself" then + batchcmds:runv("./scripts/get.sh", {"__local__"}) + elseif format == "srpm" or format == "deb" then + batchcmds:runv("make", {"install", path(package:install_rootdir(), function (p) return "PREFIX=" .. p end)}) + end + end) diff --git a/samples/Xmake/sample5.xmake.lua b/samples/Xmake/sample5.xmake.lua new file mode 100644 index 000000000..b39b764f1 --- /dev/null +++ b/samples/Xmake/sample5.xmake.lua @@ -0,0 +1,44 @@ +add_rules("mode.debug", "mode.release") + +option("opt0", {default = true, defines = "OPT0", description = "option0"}) + +namespace("ns1", function () + option("opt1", {default = true, defines = "NS1_OPT1", description = "option1"}) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_options("opt1") + if has_config("opt1") then + add_defines("HAS_NS1_OPT1") + end + + namespace("ns2", function() + option("opt2", {default = true, defines = "NS2_OPT2", description = "option2"}) + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_options("opt2") + if has_config("opt2") then + add_defines("HAS_NS2_OPT2") + end + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + add_options("opt0", "opt1", "ns2::opt2") + on_load(function (target) + if has_config("opt0") then + target:add("defines", "HAS_OPT0") + end + if has_config("opt1") then + target:add("defines", "HAS_NS1_OPT1") + end + if has_config("ns2::opt2") then + target:add("defines", "HAS_NS2_OPT2") + end + end) +end) + diff --git a/samples/Xmake/sample6.xmake.lua b/samples/Xmake/sample6.xmake.lua new file mode 100644 index 000000000..44523e593 --- /dev/null +++ b/samples/Xmake/sample6.xmake.lua @@ -0,0 +1,20 @@ +task("pack") + set_category("plugin") + on_run("main") + set_menu { + usage = "xmake pack [options] [names]", + description = "Pack binary installation packages.", + options = { + {'o', "outputdir", "kv", nil, "Set the output directory. (default: build/xpack)"}, + {nil, "basename", "kv", nil, "Set the basename of the output file."}, + {nil, "autobuild", "kv", true, "Build targets automatically."}, + {'j', "jobs", "kv", tostring(os.default_njob()), "Set the number of parallel compilation jobs." }, + {'f', "formats", "kv", "all", "Pack the given package formats.", + "e.g.", + " - xmake pack -f nsis,deb,rpm", + "values:", + values = {"nsis", "wix", "deb", "srpm", "rpm", "runself", "targz", "zip", "srctargz", "srczip"}}, + {}, + {nil, "packages", "vs", nil, "The package names."} + } + } diff --git a/samples/Xmake/sample7.xmake.lua b/samples/Xmake/sample7.xmake.lua new file mode 100644 index 000000000..b853eaeaa --- /dev/null +++ b/samples/Xmake/sample7.xmake.lua @@ -0,0 +1,162 @@ +-- define rule: markdown +rule("markdown") + set_extensions(".md", ".markdown") + on_load(function (target) + print("markdown: on_load") + end) + on_build_file(function (target, sourcefile) + print("compile %s", sourcefile) + os.cp(sourcefile, path.join(target:targetdir(), path.basename(sourcefile) .. ".html")) + end) + +-- define rule: man +rule("man") + add_imports("core.project.rule") + on_build_files(function (target, sourcefiles) + for _, sourcefile in ipairs(sourcefiles) do + print("generating man: %s", sourcefile) + end + end) + +-- define rule: c code +rule("c code") + add_imports("core.tool.compiler") + before_build_file(function (target, sourcefile) + print("before_build_file: ", sourcefile) + end) + on_build_file(function (target, sourcefile, opt) + import("core.theme.theme") + import("utils.progress") + progress.show(opt.progress, "compiling.$(mode) %s", sourcefile) + local objectfile_o = os.tmpfile() .. ".o" + local sourcefile_c = os.tmpfile() .. ".c" + os.cp(sourcefile, sourcefile_c) + compiler.compile(sourcefile_c, objectfile_o) + table.insert(target:objectfiles(), objectfile_o) + end) + after_build_file(function (target, sourcefile) + print("after_build_file: ", sourcefile) + end) + +-- define rule: stub3 +rule("stub3") + add_deps("markdown") + on_load(function (target) + print("rule(stub3): on_load") + end) + +-- define rule: stub2 +rule("stub2") + add_deps("stub3") + on_load(function (target) + print("rule(stub2): on_load") + end) + before_build(function (target) + print("rule(stub2): before_build") + end) + after_build(function (target) + print("rule(stub2): after_build") + end) + before_build_files(function (target) + print("rule(stub2): before_build_files") + end) + after_build_files(function (target) + print("rule(stub2): after_build_files") + end) + +-- define rule: stub1 +rule("stub1") + add_deps("stub2") + on_load(function (target) + print("rule(stub1): on_load") + end) + + before_build(function (target) + print("rule(stub1): before_build") + end) + after_build(function (target) + print("rule(stub1): after_build") + end) + + before_clean(function (target) + print("rule(stub1): before_clean") + end) + after_clean(function (target) + print("rule(stub1): after_clean") + end) + + before_install(function (target) + print("rule(stub1): before_install") + end) + on_install(function (target) + print("rule(stub1): on_install") + end) + after_install(function (target) + print("rule(stub1): after_install") + end) + + before_uninstall(function (target) + print("rule(stub1): before_uninstall") + end) + on_uninstall(function (target) + print("rule(stub1): on_uninstall") + end) + after_uninstall(function (target) + print("rule(stub1): after_uninstall") + end) + + before_package(function (target) + print("rule(stub1): before_package") + end) + on_package(function (target) + print("rule(stub1): on_package") + end) + after_package(function (target) + print("rule(stub1): after_package") + end) + + before_run(function (target) + print("rule(stub1): before_run") + end) + on_run(function (target) + print("rule(stub1): on_run") + end) + after_run(function (target) + print("rule(stub1): after_run") + end) + +-- define rule: stub0b +rule("stub0b") + before_build_file(function (target, sourcefile) + print("rule(stub0b): before_build_file", sourcefile) + end) + +-- define rule: stub0a +rule("stub0a") + after_build_file(function (target, sourcefile) + print("rule(stub0a): after_build_file", sourcefile) + end) + +-- define target +target("test") + + -- set kind + set_kind("binary") + + -- add rules + add_rules("stub1") + + -- add files + add_files("src/*.c|main2.c", {rules = {"stub0a", "stub0b"}}) + add_files("src/main2.c", {rules = {"stub0a", "stub0b", override = true}}) + add_files("src/man/*.in", {rule = "man"}) + add_files("src/index.md") + add_files("src/test.c.in", {rule = "c code"}) + + before_build(function (target) + print("target: before_build") + end) + + after_build(function (target) + print("target: after_build") + end) diff --git a/samples/Xmake/sample8.xmake.lua b/samples/Xmake/sample8.xmake.lua new file mode 100644 index 000000000..3f20836a5 --- /dev/null +++ b/samples/Xmake/sample8.xmake.lua @@ -0,0 +1,31 @@ +add_rules("mode.debug", "mode.release") + +interp_add_scopeapis("myscope.set_name", "myscope.add_list", {kind = "values"}) +interp_add_scopeapis("myscope.on_script", {kind = "script"}) + +myscope("hello") + set_name("foo") + add_list("value1", "value2") + on_script(function () + print("hello") + end) + +target("test") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("core.project.project") + local myscope = project.scope("myscope") + for name, scope in pairs(myscope) do + print("myscope(%s)", name) + print(" name: %s", scope:get("name")) + print(" list: %s", table.concat(scope:get("list"), ", ")) + print(" script:") + local script = scope:get("script") + if script then + script() + end + end + end) + + diff --git a/samples/Xmake/sample9.xmake.lua b/samples/Xmake/sample9.xmake.lua new file mode 100644 index 000000000..67223bc79 --- /dev/null +++ b/samples/Xmake/sample9.xmake.lua @@ -0,0 +1,51 @@ +add_rules("mode.debug", "mode.release") +set_policy("test.return_zero_on_failure", true) + +for _, file in ipairs(os.files("src/test_*.cpp")) do + local name = path.basename(file) + target(name) + set_kind("binary") + set_default(false) + add_files("src/" .. name .. ".cpp") + add_tests("default") + add_tests("args", {runargs = {"foo", "bar"}}) + add_tests("pass_output", {trim_output = true, runargs = "foo", pass_outputs = "hello foo"}) + add_tests("fail_output", {fail_outputs = {"hello2 .*", "hello xmake"}}) +end + +target("test_10") + set_kind("binary") + set_default(false) + add_files("src/compile_1.cpp") + add_tests("compile_fail", {build_should_fail = true}) + +target("test_11") + set_kind("binary") + set_default(false) + add_files("src/compile_2.cpp") + add_tests("compile_pass", {build_should_pass = true}) + +target("test_13") + set_kind("binary") + set_default(false) + add_files("src/test_1.cpp") + add_tests("stub_1", {files = "tests/stub_1.cpp", defines = "STUB_1"}) + +target("test_14") + set_kind("binary") + set_default(false) + add_files("src/test_2.cpp") + add_tests("stub_2", {files = "tests/stub_2.cpp", defines = "STUB_2"}) + +target("test_15") + set_kind("binary") + set_default(false) + add_files("src/test_1.cpp") + add_tests("stub_n", {files = "tests/stub_n*.cpp", defines = "STUB_N"}) + +target("test_timeout") + set_kind("binary") + set_default(false) + add_files("src/run_timeout.cpp") + add_tests("run_timeout", {run_timeout = 1000}) + diff --git a/vendor/grammars/xmake-lua.tmbundle b/vendor/grammars/xmake-lua.tmbundle new file mode 160000 index 000000000..2e8dfc454 --- /dev/null +++ b/vendor/grammars/xmake-lua.tmbundle @@ -0,0 +1 @@ +Subproject commit 2e8dfc454ed0f6aef121cfd6fe2be6812eeb6427 diff --git a/vendor/licenses/git_submodule/xmake-lua.tmbundle.dep.yml b/vendor/licenses/git_submodule/xmake-lua.tmbundle.dep.yml new file mode 100644 index 000000000..9a289bc65 --- /dev/null +++ b/vendor/licenses/git_submodule/xmake-lua.tmbundle.dep.yml @@ -0,0 +1,31 @@ +--- +name: xmake-lua.tmbundle +version: 2e8dfc454ed0f6aef121cfd6fe2be6812eeb6427 +type: git_submodule +homepage: https://github.com/xmake-io/xmake-lua.tmbundle +license: mit +licenses: +- sources: LICENSE + text: | + MIT License + + Copyright (c) 2022 最萌小汐 + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, includinR without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +notices: []