diff --git a/.github/workflows/bindings_lua.yml b/.github/workflows/bindings_lua.yml index 80b7f4aac48..4fd3bcde919 100644 --- a/.github/workflows/bindings_lua.yml +++ b/.github/workflows/bindings_lua.yml @@ -46,12 +46,11 @@ jobs: - name: Setup lua toolchain run: | sudo apt-get update - sudo apt-get install -y lua-busted + sudo apt-get install -y lua-busted luarocks liblua5.2-dev - name: Setup Rust toolchain uses: ./.github/actions/setup - name: Build & Test working-directory: "bindings/lua" run: | - cargo build - mv ../../target/debug/libopendal_lua.so opendal.so + sudo "PATH=$PATH" luarocks make busted test/opendal_test.lua diff --git a/Cargo.lock b/Cargo.lock index 5c96c80d1e2..d5b16a8e51e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2190,24 +2190,6 @@ dependencies = [ "linked-hash-map", ] -[[package]] -name = "lua-src" -version = "546.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb00c1380f1b4b4928dd211c07301ffa34872a239e590bd3219d9e5b213face" -dependencies = [ - "cc", -] - -[[package]] -name = "luajit-src" -version = "210.4.5+resty2cf5186" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b7992a40e602786272d84c6f2beca44a588ededcfd57b48ec6f82008a7cb97" -dependencies = [ - "cc", -] - [[package]] name = "mach" version = "0.3.2" @@ -2471,8 +2453,6 @@ checksum = "07366ed2cd22a3b000aed076e2b68896fb46f06f1f5786c5962da73c0af01577" dependencies = [ "bstr 0.2.17", "cc", - "lua-src", - "luajit-src", "mlua_derive", "num-traits", "once_cell", @@ -3566,9 +3546,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48e50df39172a3e7eb17e14642445da64996989bc212b583015435d39a58537" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" dependencies = [ "bytes", "prost-derive", @@ -3576,9 +3556,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.11.8" +version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea9b0f8cbe5e15a8a042d030bd96668db28ecb567ec37d691971ff5731d2b1b" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", "itertools", diff --git a/bindings/lua/Cargo.toml b/bindings/lua/Cargo.toml index e9e0dbcc292..fed7aa5d375 100644 --- a/bindings/lua/Cargo.toml +++ b/bindings/lua/Cargo.toml @@ -29,9 +29,15 @@ rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +default = ["mlua/lua52"] +lua52 = ["mlua", "mlua/lua52"] + [lib] crate-type = ["cdylib"] [dependencies] -mlua = { version = "0.8", features = ["lua52", "vendored", "module"] } +mlua = { version = "0.8", features = ["module"], default-features = false, optional = true } opendal.workspace = true + diff --git a/bindings/lua/README.md b/bindings/lua/README.md index b666a415dcb..42649fd4a97 100644 --- a/bindings/lua/README.md +++ b/bindings/lua/README.md @@ -19,7 +19,7 @@ print("read: ", op:read("test.txt")) ## Lua version You have to enable one of the features: lua54, lua53, lua52, lua51, luajit(52) or luau in `Cargo.toml`, according to the chosen Lua version. Default Lua version is 5.2. -## Build +## Build from source 1. Build OpenDAL LUA Interface @@ -35,6 +35,11 @@ $ cargo build --package opendal-lua --release $ cp ../../target/release/libopendal_lua.so /usr/lib/lua/5.2/opendal.so ``` +## Install from luarocks +```bash +$ luarocks make +``` + ## Usage ```bash $ lua5.2 example/fs.lua diff --git a/bindings/lua/opendal-0.1.0-1.rockspec b/bindings/lua/opendal-0.1.0-1.rockspec new file mode 100644 index 00000000000..bcd9ad3fbbc --- /dev/null +++ b/bindings/lua/opendal-0.1.0-1.rockspec @@ -0,0 +1,28 @@ +package = "opendal" +version = "0.1.0-1" + +source = { + url = "git+https://github.com/apache/incubator-opendal/", +} + +description = { + summary = "Apache OpenDAL LUA binding: access data freely. ", + detailed = [[ + OpenDAL is a data access layer that allows users to easily and efficiently retrieve data from various storage services in a unified way. + ]], + homepage = "https://opendal.apache.org/", + license = " Apache-2.0" +} + +dependencies = { + "lua >= 5.1", + "luarocks-build-rust-mlua", +} + +build = { + type = "rust-mlua", + modules = { + ["opendal"] = "opendal_lua", + }, + target_path = "../../target", +} diff --git a/bindings/lua/test/opendal_test.lua b/bindings/lua/test/opendal_test.lua index 9d7b2e5e073..a6007bdc187 100644 --- a/bindings/lua/test/opendal_test.lua +++ b/bindings/lua/test/opendal_test.lua @@ -19,10 +19,11 @@ ]] +local opendal = require("opendal") + describe("opendal unit test", function() describe("opendal fs schema", function() it("operator function in fs schema", function() - local opendal = require("opendal") local op, err = opendal.operator.new("fs",{root="/tmp"}) assert.is_nil(err) assert.is_nil(op:write("test.txt","hello world")) @@ -41,7 +42,6 @@ describe("opendal unit test", function() assert.equal(op:is_exist("test_1.txt"), false) end) it("meta function in fs schema", function() - local opendal = require("opendal") local op, err = opendal.operator.new("fs",{root="/tmp"}) assert.is_nil(err) assert.is_nil(op:write("test.txt","hello world")) @@ -60,7 +60,6 @@ describe("opendal unit test", function() end) describe("opendal memory schema", function() it("operator function in memory schema", function() - local opendal = require("opendal") local op, err = opendal.operator.new("memory",{root="/tmp"}) assert.is_nil(err) assert.is_nil(op:write("test.txt","hello world")) @@ -75,7 +74,6 @@ describe("opendal unit test", function() assert.equal(op:is_exist("test_1.txt"), false) end) it("meta function in memory schema", function() - local opendal = require("opendal") local op, err = opendal.operator.new("memory",{root="/tmp"}) assert.is_nil(err) assert.is_nil(op:write("test.txt","hello world"))