-
Notifications
You must be signed in to change notification settings - Fork 61
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
Processing custom cargo environment #89
Comments
Another possible solution and I think it is more conscious is setting |
I think the container should not write intermediate build results to the host. Let’s try to work in that direction. Sent with GitHawk |
I think it could copy For now, I'm doing the same but outside the container, it may be a temporal solution for other rangers: # removing dirs
rm -rf $(DIR)/.optimize_cache
rm -rf $(DIR)/artifacts
# create cache dir and copy sources
mkdir -p $(DIR)/.optimize_cache
cp $(DIR)/Cargo.toml $(DIR)/.optimize_cache
cp $(DIR)/Cargo.lock $(DIR)/.optimize_cache
cp -r $(DIR)/src $(DIR)/.optimize_cache/src
# run docker there
docker run --rm \
-e CARGO_TERM_COLOR=always \
--volume $(DIR)/.optimize_cache:/code \
--volume $(CONTAINER)_cache:/code/target \
--volume registry_cache:/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.12.6
# move built artifacts
mv $(DIR)/.optimize_cache/artifacts $(DIR)
# removing cache dir
rm -rf $(DIR)/.optimize_cache |
Okay, so on the happy path this is prevented by using How are you setting
What's the use case for this? |
I'd like to piggy back off of this for my use case. I'm the maintainer of wasm-deploy and I would like to implement a way for users to have a deterministic build via rust-optimizer. Here is an example of the error I'm getting
The actual target dir is located at `./target/ |
@ewoolsey rust-optimizer does not support workspaces at all and does not try to do that. workspace-optimizer compiles all contracts in |
@webmaster128 right, but workspace optimizer is not configurable enough for my use case. |
I guess the use case is our of scope for now. What we want to achieve here is minimal instructions as input in order to make reproducible builds easy. This in some places requires conventions, such as all contracts being a sub-folder of contracts. What it gives you is that source code + builder (docker image+tag) are sufficient for reproducible builds. No configs, no flags, no env variables. Just the two inputs and you can verify the build process. This makes manual verifications in gov proposals easy and tools like https://aurascan.io/contracts streamline this process. That being said, I am happy to discuss what can be improved that does not require adding additional parameters to the verification step. |
@webmaster128 Part of the reason I piggy backed off of this issue is because the solution proposed by @SteMak
Seems like it could work for me as well. Although I am also unsure how that var is correctly set. |
But where would Regarding the shell in question ( |
I mean we could have a custom |
|
That's not a problem here since we do not support custom settings anyways. This tools should exist early when it detects a |
Why are custom envs a problem? If they are set in the repo, say via a toml, then it should be the same for when someone else goes to verify the signature? I guess I don't understand why that can't be accommodated. |
I just realized that there is also |
But then again, https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir is not set in the project, right? Why would the project itself have a say where the target folder should be? This should be defined by the build environment (here the docker guest) |
What exactly are you referring to here? How can a toml config file change environment variables? |
Ah my mistake I thought the target-dir could be set via a toml. Surely someone has written a tool to extract these variables though. |
Coming back to this solution:
With the change in #124 we make sure the target folder is set by the building system (as it should be). Instead of having the mount cache or override host behaviour which was never intended, it creates a mount cache or recompile behaviour. This should be a safe default and does not change conceptually how the builders work. Providing environment variables to influence the build is discouraged since it will hurt reproducible builds. Maybe we disallow them explicitely at some point. If you don't care about reproducible builds and just want optimized Wasm, it's easier and faster to use your local toolchain with approaches like this script or community tools like cw-optimizoor. |
0.13.0 was released. Now the builder never writes into the host environment, event if you don't set the cache volume. This makes the cache optional. If you don't use it, nothing bad happens. See also the diff in the CHANGELOG for how to call it: https://github.com/CosmWasm/rust-optimizer/blob/main/CHANGELOG.md#0130---2023-06-20. For follow-up discussions, please open a new specific issue. Thanks again for bringing this problem up! |
Problem
Provide some special cargo env variables into the docker container crashes the script.
Background
I use custom
CARGO_TARGET_DIR
andCARGO_BUILD_TARGET_DIR
variables that are responsible for target folder name that istarget
by default.It is important to provide the variables to docker container as the project folder in mounted as volume and cargo shouldn't create additional
target
directory.Solution
Use corresponding env variables when constructing paths to files.
Here optimize.sh#L42 change is needed: replace
target
with"$CARGO_TARGET_DIR"
.The text was updated successfully, but these errors were encountered: