luarocks-build-xmake基于 xmake 的 luarocks 构建模块

联合创作 · 2023-10-01

luarocks-build-xmake 是一个基于 xmake 的 luarocks 构建模块,用于替换 luarocks 内置的构建系统去构建 C/C++ 模块,指定 xmake 作为构建类型,并添加 luarocks-build-xmake 依赖项。

关于 xmake 构建系统,详情见:xmake.

例子1 (带有 xmake.lua)

如果模块工程中使用了 xmake.lua 来维护构建,那么我们可以直接使用 xmake 去构建它,rockspec 文件中不需要额外的配置构建规则。

├── src
│   ├── test.c
│   └── test.h
└── xmake.lua

xmake.lua

我们需要使用 add_rules("luarocks.module") 添加针对 luarocks 模块构建规则。

add_rules("mode.debug", "mode.release")

target("example1.hello")
    add_rules("luarocks.module")
    add_files("src/test.c")

rockspec

package = "example1"
version = "1.0-1"
source = {
    url = "git://github.com/xmake-io/luarocks-build-xmake",
    tag = "example1"
}
dependencies = {
    "lua >= 5.1",
    "luarocks-build-xmake"
}
build = {
    type = "xmake",
    copy_directories = {}
}

例子2 (没有 xmake.lua)

如果模块工程中没有使用 xmake.lua 来维护,那么我们也可以使用 xmake 替代 luarocks 内置的构建来编译,只需要在 rockspec 文件中去描述构建规则。

├── src
    ├── test.c
    └── test.h

rockspec

package = "example2"
version = "1.0-1"
source = {
    url = "git://github.com/xmake-io/luarocks-build-xmake",
    tag = "example2"
}
dependencies = {
    "lua >= 5.1",
    "luarocks-build-xmake"
}
build = {
    type = "xmake",
    modules = {
        ["example2.hello"] = {
            sources = "src/test.c"
        }
    },
    copy_directories = {}
}

设置特定 xmake 版本

dependencies = {
    "lua >= 5.1",
    "luarocks-build-xmake"
}
build = {
    type = "xmake",
    variables = {
        xmake = {
            version = "2.5.1"
        }
    },
    copy_directories = {}
}

设置 xmake 编译参数

dependencies = {
    "lua >= 5.1",
    "luarocks-build-xmake"
}
build = {
    type = "xmake",
    variables = {
        xmake = {
            plat = "mingw",
            arch = "x86_64",
            mode = "debug",
            cflags = "-DTEST1",
            cc = "gcc",
            ld = "gcc",
            ldflags = "...",
            mingw = "mingw sdk path",
            vs = "2019",
            vs_runtime = "MT",
            vs_toolset = "",
            vs_sdkver = "",
        }
    },
    copy_directories = {}
}
浏览 2
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报