xmake從v2.0開始,全面支持插件模式,咱們能夠很方便的擴展實現本身的插件,而且xmake也提供了一些內建的使用插件git
咱們能夠執行下 xmake -h
看下當前支持的插件:github
Plugins: l, lua Run the lua script. m, macro Run the given macro. doxygen Generate the doxygen document. hello Hello xmake! project Create the project file.
接下來咱們介紹下本文的重點,一個簡單的hello xmake插件的開發,代碼以下:xcode
-- 定義一個名叫hello的插件任務 task("hello") -- 設置類型爲插件 set_category("plugin") -- 插件運行的入口 on_run(function () -- 顯示hello xmake! print("hello xmake!") end) -- 設置插件的命令行選項,這裏沒有任何參數選項,僅僅顯示插件描述 set_menu({ -- usage usage = "xmake hello [options]" -- description , description = "Hello xmake!" -- options , options = {} })
這個插件的文件結構以下:bash
hello - xmake.lua
如今一個最簡單的插件寫完了,那怎麼讓它被xmake檢測到呢,有三種方式:ui
add_plugindirs("./hello")
添加當前的工程的插件搜索目錄,這樣只對當前工程生效接下來,咱們嘗試運行下這個插件:lua
xmake hello
顯示結果:.net
hello xmake!
固然你能夠經過set_menu中添加一些自定義的參數,這個等後續再詳細介紹插件
最後咱們還能夠在target自定義的腳本中運行這個插件:命令行
target("demo") -- 構建以後運行插件 after_build(function (target) -- 導入task模塊 import("core.project.task") -- 運行插件任務 task.run("hello") end)