Skip to content

Commit

Permalink
Add Xmake
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 11, 2025
1 parent 09880c7 commit af56ebf
Show file tree
Hide file tree
Showing 15 changed files with 796 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

20 changes: 20 additions & 0 deletions samples/Xmake/filenames/xmake.lua
Original file line number Diff line number Diff line change
@@ -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

47 changes: 47 additions & 0 deletions samples/Xmake/sample1.xmake.lua
Original file line number Diff line number Diff line change
@@ -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
157 changes: 157 additions & 0 deletions samples/Xmake/sample2.xmake.lua
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions samples/Xmake/sample3.xmake.lua
Original file line number Diff line number Diff line change
@@ -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)
Loading

0 comments on commit af56ebf

Please sign in to comment.