Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix contracts compilation with CARGO_TARGET_DIR set #2927

Merged

Conversation

nazar-pc
Copy link
Contributor

In case CARGO_TARGET_DIR is set, build artifacts were in the wrong place and build.rs was failing. With CARGO_TARGET_DIR=/home/nazar-pc/.cache/cargo/target:

error: failed to run custom build command for `pallet-contracts-fixtures v1.0.0 (/web/subspace/polkadot-sdk/substrate/frame/contracts/fixtures)`

Caused by:
  process didn't exit successfully: `/home/nazar-pc/.cache/cargo/target/debug/build/pallet-contracts-fixtures-35d534f7ac3009e0/build-script-build` (exit status: 1)
  --- stderr
  Error: Failed to read "/tmp/.tmpiYwXfv/target/wasm32-unknown-unknown/release/dummy.wasm"

  Caused by:
      Can't read from the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }

The file was actually in /home/nazar-pc/.cache/cargo/target/wasm32-unknown-unknown/release/dummy.wasm.

@nazar-pc nazar-pc requested a review from athei as a code owner January 15, 2024 08:18
@nazar-pc nazar-pc requested a review from a team January 15, 2024 08:18
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 15, 2024 08:19
@nazar-pc nazar-pc force-pushed the fix-contracts-compilation-with-target-dir branch from 5b83fee to 9a9eb77 Compare January 15, 2024 08:33
Copy link
Member

@athei athei left a comment

Choose a reason for hiding this comment

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

Can you add the same line for the riscv build, too?

@athei athei requested a review from pgherveou January 15, 2024 11:00
@nazar-pc
Copy link
Contributor Author

nazar-pc commented Jan 15, 2024

I believe it is not necessary there due to env_clear call

@athei
Copy link
Member

athei commented Jan 15, 2024

You are right. We should probably do the same for the wasm build then. It seems more robust to remove all variables and only forward/set what we need. But let's wait for @pgherveou opinion.

@nazar-pc
Copy link
Contributor Author

I thought about that too, but with switch to huge monorepo compiling everything is extremely painful locally so I decided to not touch what seems to work fine as is. Feel free to experiment with it though.

@pgherveou
Copy link
Contributor

You are right. We should probably do the same for the wasm build then. It seems more robust to remove all variables and only forward/set what we need. But let's wait for @pgherveou opinion.

I think I tried that and it was failing for some reason. I did not investigated much more since it was working without clearing.
let met check this quickly again

@pgherveou pgherveou added the R0-silent Changes should not be mentioned in any release notes label Jan 15, 2024
@pgherveou
Copy link
Contributor

pgherveou commented Jan 15, 2024

You are right. We should probably do the same for the wasm build then. It seems more robust to remove all variables and only forward/set what we need. But let's wait for @pgherveou opinion.

I think I tried that and it was failing for some reason. I did not investigated much more since it was working without clearing. let met check this quickly again

seems to work ¯_(ツ)_/¯, let me test in docker, push an update and see if that pass CI

nvm, does not work in CI, it seems to pick up the wrong clang binary

@@ -203,6 +203,7 @@ fn invoke_wasm_build(current_dir: &Path) -> Result<()> {

let build_res = Command::new(env::var("CARGO")?)
.current_dir(current_dir)
.env("CARGO_TARGET_DIR", current_dir.join("target").display().to_string())
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldln't we just clear it if it set, instead of setting it ?
or the fixtures will end up here instead of OUT_DIR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't thought of it right away, but clearing should work as well

Copy link
Member

Choose a reason for hiding this comment

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

It has to end up wherever you expect to find them in the rest of your script. In this case current_dir/target is the same as the default. Otherwise the CI would fail. So deleting should have the same effect. But let's find out why clearing the environment doesn't work.

Copy link
Contributor

@pgherveou pgherveou Jan 15, 2024

Choose a reason for hiding this comment

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

let's stick with the current fix

if we wish to clear env, This works as well

                .env_clear()
		.envs([
			("PATH", env::var("PATH").unwrap_or_default()),
			("CARGO_HOME", env::var("CARGO_HOME").unwrap_or_default()),
			("RUSTC", env::var("RUSTC").unwrap_or_default()),
		])

@athei
Copy link
Member

athei commented Jan 15, 2024

You are right. We should probably do the same for the wasm build then. It seems more robust to remove all variables and only forward/set what we need. But let's wait for @pgherveou opinion.

I think I tried that and it was failing for some reason. I did not investigated much more since it was working without clearing. let met check this quickly again

seems to work ¯_(ツ)_/¯, let me test in docker, push an update and see if that pass CI

nvm, does not work in CI, it seems to pick up the wrong clang binary

This is weird. We don't depend on C code in our test fixtures?

@pgherveou
Copy link
Contributor

You are right. We should probably do the same for the wasm build then. It seems more robust to remove all variables and only forward/set what we need. But let's wait for @pgherveou opinion.

I think I tried that and it was failing for some reason. I did not investigated much more since it was working without clearing. let met check this quickly again

seems to work ¯_(ツ)_/¯, let me test in docker, push an update and see if that pass CI
nvm, does not work in CI, it seems to pick up the wrong clang binary

This is weird. We don't depend on C code in our test fixtures?

that's when compiling dependencies-

  --- stderr
      Updating crates.io index
     Compiling proc-macro2 v1.0.76
     Compiling unicode-ident v1.0.12
     Compiling paste v1.0.14
     Compiling polkavm-common v0.4.0
     Compiling bitflags v1.3.2
  error: linker `clang-15` not found
    |
    = note: No such file or directory (os error 2)

  error: could not compile `paste` (build script) due to previous error
  warning: build failed, waiting for other jobs to finish...
  error: could not compile `proc-macro2` (build script) due to previous error

@athei
Copy link
Member

athei commented Jan 15, 2024

Okay yes we pull in a lot of stuff for macro support. Try to forward the CC and CXX env vars to the command. Let's stick with opt-in until it works.

@bkchr
Copy link
Member

bkchr commented Jan 15, 2024

BTW, this is all already solved here. Not sure what is that complicated to just copy this..

@athei athei added the T7-smart_contracts This PR/Issue is related to smart contracts. label Jan 15, 2024
@pgherveou pgherveou removed the request for review from a team January 15, 2024 16:35
@paritytech-review-bot paritytech-review-bot bot requested a review from a team January 15, 2024 16:36
@bkchr bkchr disabled auto-merge January 18, 2024 21:18
@bkchr bkchr merged commit b4b523c into paritytech:master Jan 18, 2024
137 of 140 checks passed
bgallois pushed a commit to duniter/duniter-polkadot-sdk that referenced this pull request Mar 25, 2024
In case `CARGO_TARGET_DIR` is set, build artifacts were in the wrong
place and `build.rs` was failing. With
`CARGO_TARGET_DIR=/home/nazar-pc/.cache/cargo/target`:
```
error: failed to run custom build command for `pallet-contracts-fixtures v1.0.0 (/web/subspace/polkadot-sdk/substrate/frame/contracts/fixtures)`

Caused by:
  process didn't exit successfully: `/home/nazar-pc/.cache/cargo/target/debug/build/pallet-contracts-fixtures-35d534f7ac3009e0/build-script-build` (exit status: 1)
  --- stderr
  Error: Failed to read "/tmp/.tmpiYwXfv/target/wasm32-unknown-unknown/release/dummy.wasm"

  Caused by:
      Can't read from the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }
```

The file was actually in
`/home/nazar-pc/.cache/cargo/target/wasm32-unknown-unknown/release/dummy.wasm`.
@nazar-pc nazar-pc deleted the fix-contracts-compilation-with-target-dir branch April 3, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T7-smart_contracts This PR/Issue is related to smart contracts.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants