Skip to content

Comments

fix: fix complex cargo struct project build error#1

Closed
oowl wants to merge 2 commits intomlua-rs:mainfrom
oowl:fix/cargo-dest-issues
Closed

fix: fix complex cargo struct project build error#1
oowl wants to merge 2 commits intomlua-rs:mainfrom
oowl:fix/cargo-dest-issues

Conversation

@oowl
Copy link

@oowl oowl commented Jun 27, 2023

use the current directory as the cargo build target. If you want to know more information, please check apache/opendal#2558

Signed-off-by: oowl <[email protected]>
@khvzak
Copy link
Member

khvzak commented Jun 27, 2023

Thanks!
I'll take a look to the issue to understand more.

Also, would setting CARGO_TARGET_DIR env in CI solve the issue? My only concern is when the env forcely set, it would not inherit external defs.

@oowl
Copy link
Author

oowl commented Jun 28, 2023

@khvzak I am not just want to resolve CI build failed
In here, you can see the project struct

incubator-opendal/bindings/lua
╰─$ ls
Cargo.toml  example  lopendal-0.1.0-1.rockspec  README.md  src  target  test

if i want to cargo build in current directory, target directory will be created in incubator-opendal/target, so in luarocks-build-rust-mlua, it except to copy opendal.so from incubator-opendal/bindings/lua/target/release directory, I think we can not make sure cargo build output in current directory, so I have forced cargo output in current directory.

@oowl oowl changed the title fix: fix cargo sub cargo.toml build error fix: fix complex cargo struct project build error Jun 28, 2023
end

table.insert(cmd, "cargo build --release --features " .. table.concat(features, ","))
table.insert(cmd, "CARGO_TARGET_DIR=./target cargo build --release --features " .. table.concat(features, ","))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding @khvzak's concern:

My only concern is when the env forcely set, it would not inherit external defs.

What do we know / can we assume about the shell this command will run in? If it's a POSIX shell we can avoid overriding an existing variable while still setting it if not:

Suggested change
table.insert(cmd, "CARGO_TARGET_DIR=./target cargo build --release --features " .. table.concat(features, ","))
table.insert(cmd, "CARGO_TARGET_DIR=${CARGO_TARGET_DIR:=./target} cargo build --release --features " .. table.concat(features, ","))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in opendal use case, we do not just want to avoid overriding it , the root case is https://github.com/khvzak/luarocks-build-rust-mlua/blob/main/src/luarocks/build/rust-mlua.lua#L74 can not make sure this path is correct

Copy link
Author

@oowl oowl Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I know your mean, That makes sense. we can not pollute some env.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I still think we need to resolve the path problem, make luarocks-build-rust-mlua find correct target path, my PR seems like some tricks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One can find the correct target path, but it's a PITA. If you have something to parse JSON available, you can query cargo for it:

$ cargo test -q --no-run --message-format=json | jq 'select(.reason == "compiler-artifact" and .target.test and (.target.kind | index("bin"))) | .executable'

Obviously adjust for release or other builds and for just getting the directory if you won't want the final executable name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a PR with a proposed fix: #2

Instead of rewriting CARGO_TARGET_DIR, can you set the correct path in rockspec file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @khvzak @alerque !

@oowl oowl closed this Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants