PageSourceSearch

https://openxlings.github.io/en/assets/js/b0e6d693.fa4fa875.js

js openxlings.github.io collected 2026-10-03 09:44:07 UTC 10,602 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkopenxlings_github_io=globalThis.webpackChunkopenxlings_github_io||[]).push([[374],{4364(e,n,s){s.r(n),s.d(n,{assets:()=>c,contentTitle:()=>t,default:()=>o,frontMatter:()=>r,metadata:()=>i,toc:()=>a});const i=JSON.parse('{"id":"xpkg/create-xpkg","title":"\u521b\u5efa XPackage","description":"XPackage\uff08xpkg\uff09\u662f xlings \u7684\u5305\u5b9a\u4e49\u683c\u5f0f\u3002\u6bcf\u4e2a xpkg \u662f\u4e00\u4e2a Lua \u6587\u4ef6\uff0c\u5b9a\u4e49\u4e86\u5305\u7684\u5143\u4fe1\u606f\u3001\u7248\u672c\u5217\u8868\u548c\u5b89\u88c5/\u914d\u7f6e/\u5378\u8f7d\u903b\u8f91\u3002","source":"@site/docs/xpkg/create-xpkg.md","sourceDirName":"xpkg","slug":"/xpkg/create-xpkg","permalink":"/en/docs/xpkg/create-xpkg","draft":false,"unlisted":false,"editUrl":"https://github.com/openxlings/openxlings.github.io/edit/main/docs/xpkg/create-xpkg.md","tags":[],"version":"current","sidebarPosition":1,"frontMatter":{"sidebar_position":1,"title":"\u521b\u5efa XPackage"},"sidebar":"docsSidebar","previous":{"title":"Sandbox \u6c99\u7bb1","permalink":"/en/docs/guide/sandbox"},"next":{"title":"XPackage \u89c4\u8303","permalink":"/en/docs/xpkg/xpkg-spec"}}');var l=s(4848),d=s(8453);const r={sidebar_position:1,title:"\u521b\u5efa XPackage"},t="\u521b\u5efa XPackage",c={},a=[{value:"\u57fa\u672c\u7ed3\u6784",id:"\u57fa\u672c\u7ed3\u6784",level:2},{value:"Hook \u51fd\u6570",id:"hook-\u51fd\u6570",level:2},{value:"\u5e38\u7528 API",id:"\u5e38\u7528-api",level:2},{value:"xvm\uff08\u7248\u672c\u7ba1\u7406\uff09",id:"xvm\u7248\u672c\u7ba1\u7406",level:3},{value:"system\uff08\u7cfb\u7edf\u64cd\u4f5c\uff09",id:"system\u7cfb\u7edf\u64cd\u4f5c",level:3},{value:"log\uff08\u65e5\u5fd7\uff09",id:"log\u65e5\u5fd7",level:3},{value:"\u5305\u7c7b\u578b",id:"\u5305\u7c7b\u578b",level:2},{value:"\u7248\u672c\u6765\u6e90",id:"\u7248\u672c\u6765\u6e90",level:2},{value:"\u63d0\u4ea4\u5230\u5305\u7d22\u5f15",id:"\u63d0\u4ea4\u5230\u5305\u7d22\u5f15",level:2}];function x(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",li:"li",ol:"ol",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,d.R)(),...e.components};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(n.header,{children:(0,l.jsx)(n.h1,{id:"\u521b\u5efa-xpackage",children:"\u521b\u5efa XPackage"})}),"\n",(0,l.jsx)(n.p,{children:"XPackage\uff08xpkg\uff09\u662f xlings \u7684\u5305\u5b9a\u4e49\u683c\u5f0f\u3002\u6bcf\u4e2a xpkg \u662f\u4e00\u4e2a Lua \u6587\u4ef6\uff0c\u5b9a\u4e49\u4e86\u5305\u7684\u5143\u4fe1\u606f\u3001\u7248\u672c\u5217\u8868\u548c\u5b89\u88c5/\u914d\u7f6e/\u5378\u8f7d\u903b\u8f91\u3002"}),"\n",(0,l.jsx)(n.h2,{id:"\u57fa\u672c\u7ed3\u6784",children:"\u57fa\u672c\u7ed3\u6784"}),"\n",(0,l.jsx)(n.p,{children:"\u4e00\u4e2a\u6700\u5c0f\u7684 xpkg \u6587\u4ef6\uff1a"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-lua",children:'package = {\n    spec = "1",\n\n    -- \u57fa\u672c\u4fe1\u606f\n    name = "myapp",\n    description = "My awesome application",\n    authors = {"Your Name"},\n    licenses = {"MIT"},\n    repo = "https://github.com/you/myapp",\n\n    -- \u5305\u7c7b\u578b\n    type = "package",\n    archs = { "x86_64" },\n    status = "stable",  -- dev, stable, deprecated\n    categories = { "tool" },\n    keywords = { "myapp", "tool" },\n\n    -- \u63d0\u4f9b\u7684\u53ef\u6267\u884c\u6587\u4ef6\n    programs = { "myapp" },\n\n    -- \u542f\u7528\u591a\u7248\u672c\u7ba1\u7406\n    xvm_enable = true,\n\n    -- \u7248\u672c\u5b9a\u4e49\uff08\u6309\u5e73\u53f0\uff09\n    xpm = {\n        linux = {\n            ["latest"] = { ref = "1.0.0" },\n            ["1.0.0"] = "https://example.com/myapp-1.0.0-linux-x86_64.tar.gz",\n        },\n        windows = {\n            ["latest"] = { ref = "1.0.0" },\n            ["1.0.0"] = "https://example.com/myapp-1.0.0-windows-x86_64.zip",\n        },\n    },\n}\n\n-- \u5bfc\u5165 xpkg \u5e93\nimport("xim.libxpkg.log")\nimport("xim.libxpkg.system")\nimport("xim.libxpkg.xvm")\n\n-- \u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5\nfunction installed()\n    return xvm.has(package.name)\nend\n\n-- \u5b89\u88c5\u903b\u8f91\nfunction install()\n    -- package.install_dir \u662f xlings \u81ea\u52a8\u8bbe\u7f6e\u7684\u5b89\u88c5\u76ee\u5f55\n    log.info("installing %s to %s", package.name, package.install_dir)\n    -- \u89e3\u538b\u4e0b\u8f7d\u7684\u6587\u4ef6\uff08xlings \u81ea\u52a8\u4e0b\u8f7d\u5230 package.install_dir\uff09\n    return true\nend\n\n-- \u5b89\u88c5\u54
10e\u914d\u7f6e\uff08\u6ce8\u518c\u7248\u672c\u3001\u521b\u5efa shim \u7b49\uff09\nfunction config()\n    xvm.add(package.name)\n    return true\nend\n\n-- \u5378\u8f7d\u903b\u8f91\nfunction uninstall()\n    xvm.remove(package.name)\n    return true\nend\n'})}),"\n",(0,l.jsx)(n.h2,{id:"hook-\u51fd\u6570",children:"Hook \u51fd\u6570"}),"\n",(0,l.jsx)(n.p,{children:"xpkg \u652f\u6301\u4ee5\u4e0b hook \u51fd\u6570\uff1a"}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"Hook"}),(0,l.jsx)(n.th,{children:"\u8c03\u7528\u65f6\u673a"}),(0,l.jsx)(n.th,{children:"\u8bf4\u660e"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:"installed()"})}),(0,l.jsx)(n.td,{children:"\u5b89\u88c5\u524d"}),(0,l.jsxs)(n.td,{children:["\u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5\uff0c\u8fd4\u56de ",(0,l.jsx)(n.code,{children:"true"})," \u5219\u8df3\u8fc7\u5b89\u88c5"]})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:"install()"})}),(0,l.jsx)(n.td,{children:"\u4e0b\u8f7d\u5b8c\u6210\u540e"}),(0,l.jsx)(n.td,{children:"\u6267\u884c\u5b89\u88c5\u64cd\u4f5c\uff08\u89e3\u538b\u3001\u7f16\u8bd1\u7b49\uff09"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:"config()"})}),(0,l.jsx)(n.td,{children:"\u5b89\u88c5\u5b8c\u6210\u540e"}),(0,l.jsx)(n.td,{children:"\u914d\u7f6e\u73af\u5883\uff08\u6ce8\u518c\u7248\u672c\u3001\u8bbe\u7f6e PATH \u7b49\uff09"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:"uninstall()"})}),(0,l.jsx)(n.td,{children:"\u5378\u8f7d\u65f6"}),(0,l.jsx)(n.td,{children:"\u6e05\u7406\u5b89\u88c5\u7684\u6587\u4ef6\u548c\u914d\u7f6e"})]})]})]}),"\n",(0,l.jsx)(n.h2,{id:"\u5e38\u7528-api",children:"\u5e38\u7528 API"}),"\n",(0,l.jsx)(n.h3,{id:"xvm\u7248\u672c\u7ba1\u7406",children:"xvm\uff08\u7248\u672c\u7ba1\u7406\uff09"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-lua",children:'import("xim.libxpkg.xvm")\n\nxvm.has("gcc")           -- \u68c0\u67e5\u662f\u5426\u5df2\u6ce8\u518c\nxvm.add("gcc")           -- \u6ce8\u518c\u5f53\u524d\u7248\u672c\nxvm.remove("gcc")        -- \u79fb\u9664\u7248\u672c\u6ce8\u518c\n'})}),"\n",(0,l.jsx)(n.h3,{id:"system\u7cfb\u7edf\u64cd\u4f5c",children:"system\uff08\u7cfb\u7edf\u64cd\u4f5c\uff09"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-lua",children:'import("xim.libxpkg.system")\n\nsystem.exec("make install")       -- \u6267\u884c\u547d\u4ee4\nsystem.xpkgdir()                  -- \u83b7\u53d6 xpkg \u6570\u636e\u76ee\u5f55\n'})}),"\n",(0,l.jsx)(n.h3,{id:"log\u65e5\u5fd7",children:"log\uff08\u65e5\u5fd7\uff09"}),"\n",(0,l.jsx)(n.pre,{children:(0,l.jsx)(n.code,{className:"language-lua",children:'import("xim.libxpkg.log")\n\nlog.info("message: %s", value)\nlog.warn("warning: %s", value)\n'})}),"\n",(0,l.jsx)(n.h2,{id:"\u5305\u7c7b\u578b",children:"\u5305\u7c7b\u578b"}),"\n",(0,l.jsxs)(n.table,{children:[(0,l.jsx)(n.thead,{children:(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.th,{children:"type \u503c"}),(0,l.jsx)(n.th,{children:"\u8bf4\u660e"})]})}),(0,l.jsxs)(n.tbody,{children:[(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:'"package"'})}),(0,l.jsx)(n.td,{children:"\u666e\u901a\u8f6f\u4ef6\u5305"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:'"config"'})}),(0,l.jsx)(n.td,{children:"\u73af\u5883\u914d\u7f6e\u5305\uff08\u5982\u955c\u50cf\u914d\u7f6e\uff09"})]}),(0,l.jsxs)(n.tr,{children:[(0,l.jsx)(n.td,{children:(0,l.jsx)(n.code,{children:'"pkgindex"'})}),(0,l.jsx)(n.td,{children:"\u5305\u7d22\u5f15\u4ed3\u5e93"})]})]})]}),"\n",(0,l.jsx)(n.h2,{id:"\u7248\u672c\u6765\u6e90",children:"\u7248\u672c\u6765\u6e90"}),"\n",(0,l.jsxs)(n.p,{children:[(0,l.jsx)(n.code,{children:"xpm"})," \u4e2d\u7248\u672c\u7684\u503c\u53ef\u4ee5\u662f\uff1a"]}),"\n",(0,l.jsxs)(n.ul,{children:["\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:"URL \u5b57\u7b26\u4e32"}),"\uff1a\u76f4\u63a5\u4e0b\u8f7d\u5730\u5740"]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:(0,l.jsx)(n.code,{children:'"XLINGS_RES"'})}),"\uff1a\u4ece xlings \u5b98\u65b9\u8d44\u6e90\u7ad9\u4e0b\u8f7d"]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsxs)(n.strong,{children:["\u5bf9\u8c61 ",(0,l.jsx)(n.code,{children:"{}"})]}),"\uff1a\u7a7a\u5bf9\u8c61\uff0c\u8868\u793a\u8be5\u7248\u672c\u53ef\u7528\u4f46\u65e0\u9700\u4e0b\u8f7d\uff08\u5982\u7cfb\u7edf\u81ea\u5e26\uff09"]}),"\n",(0,l.jsxs)(n.li,{children:[(0,l.jsx)(n.strong,{children:(0,l.jsx)(n.code,{children:'{ ref = "x.y.z" }'})}),"\uff1a",(0,l.jsx)(n.code,{children:"latest"})," \u7b49\u522b\u540d\u6307\u5411\u7684\u5b9e\u9645\u7248\u672c"]}),"\n"]}),"\n",(0,l.jsx)(n.h2,{id:"\u63d0\u4ea4\u5230\u5305\u7d22\u5f15",children:"\u63d0\u4ea4\u5230\u5305\u7d22\u5f15"}),"\n",(0,l.jsxs)(n.p,{children:["\u521b\u5efa\u597d xpkg \u540e\uff0c\u53ef\u4ee5\u63d0\u4ea4\u5230 ",(0,l.jsx)(n.a,{href:"https://github.com/openxlings/xim-pkgindex",children:"xim-pkgindex"})," \u4ed3\u5e93\uff1a"]}),"\n",(0,l.jsxs)(n.ol,{children:["\n",(0,l.jsxs)(n.li,{children:["Fork ",(0,l.jsx)(n.code,{children:"xim-pkgindex"})," \u4ed3\u5e93"]}
1),"\n",(0,l.jsxs)(n.li,{children:["\u5c06 Lua \u6587\u4ef6\u653e\u5230 ",(0,l.jsx)(n.code,{children:"pkgs/<\u9996\u5b57\u6bcd>/"})," \u76ee\u5f55\u4e0b\uff08\u5982 ",(0,l.jsx)(n.code,{children:"pkgs/m/myapp.lua"}),"\uff09"]}),"\n",(0,l.jsx)(n.li,{children:"\u63d0\u4ea4 Pull Request"}),"\n"]})]})}function o(e={}){const{wrapper:n}={...(0,d.R)(),...e.components};return n?(0,l.jsx)(n,{...e,children:(0,l.jsx)(x,{...e})}):x(e)}},8453(e,n,s){s.d(n,{R:()=>r,x:()=>t});var i=s(6540);const l={},d=i.createContext(l);function r(e){const n=i.useContext(d);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function t(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(l):e.components||l:r(e.components),i.createElement(d.Provider,{value:n},e.children)}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.