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

Add support for offline compilation #38

Open
bevsxyz opened this issue Nov 6, 2021 · 6 comments
Open

Add support for offline compilation #38

bevsxyz opened this issue Nov 6, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@bevsxyz
Copy link

bevsxyz commented Nov 6, 2021

I wish to use rust-script with my i3blocks to obtain system temperature. My script works. But it required internet for compilation, and hence I could not run it during startup, and my bar ignored it completely. Can we make use of the cache and offer an offline compilation mode?

cargo-script issue
Modes suggestion

@bevsxyz
Copy link
Author

bevsxyz commented Nov 6, 2021

Another solution would be only to compile when the source files have changed. This would allow the reuse of the cached binaries.
Here the ideal way to go about it would be to save the binary as a hidden dotfile in the source directory of the script. If there is no binary or the script modified time is later than the binary created time, then compile the binary.

@fornwall fornwall added the enhancement New feature or request label Nov 10, 2021
@fornwall
Copy link
Owner

@bevsxyz Thanks for creating the issue!

I'm a bit uncertain about exactly what --offline does? I see https://doc.rust-lang.org/cargo/faq.html stating:

The --offline flag was added in Rust 1.36.0. This flag tells Cargo to not access the network, and try to proceed with available cached data if possible

But I'm uncertain about what that exactly does - why doesn't cargo proceed available cached data if possible by default? Is it to check for updates (but does it do that even in the existence of a Cargo.lock file)?

In general I don't see that rust-script requires internet access - after the initial build, I can turn off internet access and it still runs. Do you have more details about when it doesn't work, but when the cargo --offline flag would make it work?

As seen above I don't really understand the current situation :), but perhaps we can move towards "offline by default when possible" - not only to work better without internet access, but also to reduce the overhead of running script (avoid slow network access when running a script) and reproducibility.

@bevsxyz
Copy link
Author

bevsxyz commented Nov 30, 2021

@fornwall sorry about the delayed reply. I am not sure either of --offline. But what I was thinking of was that keep a hidden binary in the directory of the script and only attempt to compile if the timestamp of this binary is outdated to that of the script. My issue was that for some reason i3bar stopped showing the script output when I restarted my system. The Perl script I have works like a charm. There are some speedups with rust-script and I'd like to use it for more stuff in the future.

Perhaps this way of relying on time-stamp we may not have to call cargo every time and avoid that overhead.

@Blisto91
Copy link
Contributor

Blisto91 commented Apr 26, 2022

Here are some of the original offline mode issues/comments if that helps with clarification.
rust-lang/cargo#4686
rust-lang/cargo#5655
rust-lang/cargo#5655 (comment)
rust-lang/cargo#6934

The stabilization proposal give a pretty good tldr i think if it still holds true

The offline mode behavior is fairly straightforward. An overview of when running in offline mode:

  • The resolver will avoid updating the index, and if the required packages are already downloaded, then it will proceed as normal. If the required packages are not available, then it will give an error with a hint to run without offline mode.

  • If the index has never been downloaded, it will give an error suggesting running without offline.

  • Commands that must use the network, like cargo publish, provide a straightforward error message that it cannot be used in offline mode.

@Blisto91
Copy link
Contributor

@fornwall The commit where you added the --offline flag to cargo makes it so scripts that require dependencies outside of std will fail unless they have already been downloaded prior.
So if i'm starting fresh the example in the readme with rand will fail because i both don't have the index downloaded nor the rand dependency. I have to compile a equivalent rust project outside of rust-script before it will succeed. (This is with internet connected)

It should only apply the offline flag if we don't have an internet connection. Tho i dunno how easy that would be or is there is a better method. Or if the offline flag even does what we want from this feature.

@fornwall
Copy link
Owner

The commit where you added the --offline flag to cargo makes it so scripts that require dependencies outside of std will fail unless they have already been downloaded prior.

@Blisto91 Thanks, reverted now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants