# android xmake f -p android -a arm64-v8a xmake b xmake f -p android -a armeabi-v7a xmake b xmake f -p android -a x86_64 xmake b # ios xmake f -p iphoneos -a ... xmake b # macos xmake f -p macosx -a ... xmake b # linux xmake f -p linux -a ... xmake b # windows xmake f -p mingw -a ... xmake b
local frameworks = {} for _, arch inipairs(pari['iphoneos']) do table.insert(frameworks, " -framework " .. path.join("build/iphoneos", arch, "release/qjs.framework")) end for _, arch inipairs(pari['macosx']) do table.insert(frameworks, " -framework " .. path.join("build/macosx", arch, "release/qjs.framework")) end
local g_platform = nil local g_arch = nil local g_mode = nil local g_verbose = false local g_execv = nil-- 非 script lifecyle hook scope, 非 on_run 函数无法获取到 os 模块的扩展函数
-- help function localfunctionindexOf(array, value) for i, v inipairs(array) do if v == value then return i end end returnnil end
localfunctionprintTable(t, indent) indent = indent or0 local indentStr = string.rep(" ", indent) iftype(t) ~= "table"then print(indentStr .. tostring(t)) return end
print(indentStr .. "{") for k, v inpairs(t) do local keyStr = tostring(k) iftype(v) == "table"then print(indentStr .. " " .. keyStr .. " = ") printTable(v, indent + 1) else local valueStr = tostring(v) print(indentStr .. " " .. keyStr .. " = " .. valueStr) end end print(indentStr .. "}") end -- help function -- end
localfunctionxmakeBuild() if g_platform and g_arch then print("🔥 ".. g_platform .. "🌹 " .. g_arch) end localconfig = { "f" } if g_platform then table.insert(config, "-p") table.insert(config, g_platform) end if g_arch then table.insert(config, "-a") table.insert(config, g_arch) end if g_mode then table.insert(config, "-m") table.insert(config, "debug") end print("⛰️ xmakeBuild: " .. table.concat(config, ", ")) -- printTable(os) -- printTable(sudo) g_execv("xmake", config)
localpackage = {"package", "-P", "."} if g_verbose then table.insert(package, "-v") end g_execv("xmake", package) end
localfunctionbuildForPlatformArch() local hasTarget = false local target_arch = g_platform_arch[g_platform] if target_arch then if g_arch then -- build specific arch if indexOf(target_arch, g_arch) then xmakeBuild() hasTarget = true end else -- build all arch for _, arch inipairs(target_arch) do g_arch = arch xmakeBuild() end hasTarget = true end end ifnot hasTarget then p = g_platform or"Unknown platform" a = g_arch or"Unknown architecture" print("🍄" .. p .. "-".. a .. " not supported!") end end
on_run(function() import("core.base.option") g_platform = option.get("platform") g_arch = option.get("arch") g_mode = option.get("debug") g_verbose = option.get("verbose") g_execv = os.execv -- printTable(os) if g_platform or g_arch then buildForPlatformArch() else xmakeBuild() end end)
--!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, TBOOX Open Source Group. -- -- @author ruki -- @file xmake.lua --
-- support add_files("Info.plist") add_deps("xcode.info_plist")
-- we must set kind before target.on_load(), may we will use target in on_load() on_load(function(target) print('[🍎] framework2...') -- get framework directory local targetdir = target:targetdir() local bundledir = path.join(targetdir, target:basename() .. ".framework") target:data_set("xcode.bundle.rootdir", bundledir)
-- get contents and resources directory local contentsdir = target:is_plat("macosx") andpath.join(bundledir, "Versions", "A") or bundledir local resourcesdir = path.join(contentsdir, "Resources") target:data_set("xcode.bundle.contentsdir", contentsdir) target:data_set("xcode.bundle.resourcesdir", resourcesdir)
-- set target info for framework ifnot target:get("kind") then target:set("kind", "shared") end target:set("filename", target:basename())
-- register clean files for `xmake clean` target:add("cleanfiles", bundledir) end)
before_build(function(target)
-- get framework directory local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) local contentsdir = path.absolute(target:data("xcode.bundle.contentsdir")) local headersdir = path.join(contentsdir, "Headers.tmp", target:basename())
-- copy header files to the framework directory local srcheaders, dstheaders = target:headerfiles(headersdir) if srcheaders and dstheaders then local i = 1 for _, srcheader inipairs(srcheaders) do local dstheader = dstheaders[i] if dstheader then os.vcp(srcheader, dstheader) end i = i + 1 end end ifnotos.isdir(headersdir) then os.mkdir(headersdir) end end)
-- get framework directory local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) local contentsdir = target:data("xcode.bundle.contentsdir") local resourcesdir = target:data("xcode.bundle.resourcesdir") local headersdir = path.join(contentsdir, "Headers")
-- do build if changed depend.on_changed(function()
-- trace progress info progress.show(opt.progress, "${color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir))
-- copy target file ifnotos.isdir(contentsdir) then os.mkdir(contentsdir) end os.vcp(target:targetfile(), contentsdir)
if target:is_shared() then -- change rpath -- @see https://github.com/xmake-io/xmake/issues/2679#issuecomment-1221839215 local filename = path.filename(target:targetfile()) local targetfile = path.join(contentsdir, filename) local rpath = path.relative(contentsdir, path.directory(bundledir)) os.vrunv("install_name_tool", {"-id", path.join("@rpath", rpath, filename), targetfile}) end
-- copy resource files local srcfiles, dstfiles = target:installfiles(resourcesdir) if srcfiles and dstfiles then local i = 1 for _, srcfile inipairs(srcfiles) do local dstfile = dstfiles[i] if dstfile then os.vcp(srcfile, dstfile) end i = i + 1 end end
-- link Versions/Current -> Versions/A -- only for macos, @see https://github.com/xmake-io/xmake/issues/2765 if target:is_plat("macosx") then local oldir = os.cd(path.join(bundledir, "Versions")) os.tryrm("Current") os.ln("A", "Current")
-- link bundledir/* -> Versions/Current/* local target_filename = path.filename(target:targetfile()) os.cd(bundledir) os.tryrm("Headers") os.tryrm("Resources") os.tryrm(target_filename) os.tryrm("Info.plist") os.ln("Versions/Current/Headers", "Headers") ifos.isdir(resourcesdir) then os.ln("Versions/Current/Resources", "Resources") end os.ln(path.join("Versions/Current", target_filename), target_filename) os.cd(oldir) end
-- do codesign, only for dynamic library local codesign_skip = target:values("xcode.codesign_skip") or get_config("xcode_codesign_skip") if target:is_shared() andnot codesign_skip then local codesign_identity = target:values("xcode.codesign_identity") or get_config("xcode_codesign_identity") if target:is_plat("macosx") or (target:is_plat("iphoneos") and target:is_arch("x86_64", "i386")) then codesign_identity = nil end codesign(contentsdir, codesign_identity) end end, {dependfile = target:dependfile(bundledir), files = {bundledir, target:targetfile()}, changed = target:is_rebuilt()}) end)
on_install(function(target) import("xcode.application.build", {alias = "appbuild", rootdir = path.join(os.programdir(), "rules")}) local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) local installdir = target:installdir() if installdir then ifnotos.isdir(installdir) then os.mkdir(installdir) end os.vcp(bundledir, installdir, {symlink = true}) end end)
on_uninstall(function(target) local bundledir = path.absolute(target:data("xcode.bundle.rootdir")) local installdir = target:installdir() os.tryrm(path.join(installdir, path.filename(bundledir))) end)
functionindexOf(array, value) for i, v inipairs(array) do if v == value then return i end end returnnil end
functionxmakeBuild(platf, archf) if platf and archf then print("🔥 ".. platf .. "🌹 " .. archf) end localconfig = { "f" } if platf then table.insert(config, "-p") table.insert(config, platf) end if archf then table.insert(config, "-a") table.insert(config, archf) end os.execv("xmake", config) os.execv("xmake", { "package", "-P", "."}) end
functionbuildForPlatformArch(platf, archf) local hasTarget = false local archs = pari[platf] if archs then if archf then if indexOf(archs, archf) then xmakeBuild(platf, archf) hasTarget = true end else for _, arch inipairs(archs) do xmakeBuild(platf, arch) end hasTarget = true end end ifnot hasTarget then platf = platf or"Unknown platform" archf = archf or"Unknown architecture" print("🍄" .. platf .. "-".. archf .. " not supported!") end end
functionmain() local platf = option.get("platform") local archf = option.get("arch") if platf or arch then buildForPlatformArch(platf, archf) else xmakeBuild() end end
localfunctionindexOf(array, value) for i, v inipairs(array) do if v == value then return i end end returnnil end
localfunctionprintTable(t, indent) indent = indent or0 local indentStr = string.rep(" ", indent) iftype(t) ~= "table"then print(indentStr .. tostring(t)) return end
print(indentStr .. "{") for k, v inpairs(t) do local keyStr = tostring(k) iftype(v) == "table"then print(indentStr .. " " .. keyStr .. " = ") printTable(v, indent + 1) else local valueStr = tostring(v) print(indentStr .. " " .. keyStr .. " = " .. valueStr) end end print(indentStr .. "}") end
localfunctionxmakeBuild(platf, archf, execvFn) if platf and archf then print("🔥 ".. platf .. "🌹 " .. archf) end localconfig = { "f" } if platf then table.insert(config, "-p") table.insert(config, platf) end if archf then table.insert(config, "-a") table.insert(config, archf) end print("⛰️ xmakeBuild: " .. table.concat(config, ", ")) printTable(os) printTable(sudo) execvFn("xmake", config) execvFn("xmake", { "package", "-P", "."}) -- "--verbose" end
localfunctionbuildForPlatformArch(platf, archf, execvFn) local hasTarget = false local archs = pari[platf] if archs then if archf then if indexOf(archs, archf) then xmakeBuild(platf, archf, execvFn) hasTarget = true end else for _, arch inipairs(archs) do xmakeBuild(platf, arch, execvFn) end hasTarget = true end end ifnot hasTarget then platf = platf or"Unknown platform" archf = archf or"Unknown architecture" print("🍄" .. platf .. "-".. archf .. " not supported!") end end
on_run(function() import("core.base.option") local platf = option.get("platform") local archf = option.get("arch") printTable(os) if platf or arch then buildForPlatformArch(platf, archf, os.execv) else xmakeBuild(nil, nil, os.execv) end end)
主要就是在非on_run scope 定义的 local function 中,无法访问到 os 模块的扩展函数 execv, 所以这里通过将 execv function 传递到函数中去. 具体修复方案等待后续排查…
Only some readonly interfaces (for example: os.getenv, os.arch) in the os module can be used in the description scope. Other interfaces can only be used in the script domain, for example: os.cp, os .rmetc.
--rule("xcode.framework") ++rule("xcode.framework2") # do codesign, only for dynamic library --local codesign_skip = target:values("xcode.codesign_skip") ++local codesign_skip = target:values("xcode.codesign_skip") or get_config("xcode_codesign_skip") if target:is_shared() and not codesign_skip then
target("qjs") set_kind("shared") add_files("quickjs.c", "libregexp.c", "libunicode.c", "cutils.c", "quickjs-libc.c", "libbf.c") add_headerfiles("*.h") add_includedirs(".") if is_plat("linux") and get_config("arch") == "x86_64" then -- 使用 add_toolchain 来设置工具链 在 linux x86 上可以编译 arm,x86, linux arm 上只能编译 arm set_arch("x86_64") set_toolchains("gcc") end if is_plat("macosx", "iphoneos", "iphonesimulator") then ++add_rules("xcode.framework2") add_files("Info.plist") ++add_values("xcode.codesign_skip", true) end on_load(function (target) target:add("defines", "_GNU_SOURCE" ) end)