10 ms·
Coming from C/C++. Is working with the online package manager (Cargo?) mandatory? Or is there a sustainable way of working/developing with Rust while completely
by jakobdabo 7y ago
Coming from C/C++. Is working with the online package manager (Cargo?) mandatory? Or is there a sustainable way of working/developing with Rust while completely offline?
I'd like to start a project, manually import libraries (downloaded manually, no dependency hell), read documentation, etc. Is it possible?
- steveklabnik 7y agoCargo can work offline. It’s a requirement of the Firefox and Debian build systems, for example. You can also use rustc without cargo if you really want, but Cargo is really good, so I don’t particularly recommend it.
- mrbonner 7y agoDoes that mean it only needs internet for the first build. And then, subsequent builds won’t need internet connection (if I don’t add new dependencies, of course), kind of like Maven?
- sanxiyn 7y agoNo, you can do everything, including the first build, offline.
- mrbonner 7y agoSorry, I should’ve been clearer: I need cargo to be online the 1st time so that it could resolve my dependencies for me online the 1st time because I don’t want to setup local repos and stuff. Thanks
- pitaj 7y agoIf you use dependencies from crates.io or other online sources, then yes you'd need to download those somehow. But that can be done separately, on an entirely different computer if you wanted.
- ucarion 7y agoYup, that works! It also downloads docs so you can `cargo doc` and then you can peruse the generated docs for all of your dependencies.
- steveklabnik 7y agoTo be clear, it downloads the source code, and then “cargo doc” builds them from the source.
- joseluis 7y agoThat's the usual way it's done. It should be technically possible to replicate cargo's functionality by predownloading the dependencies and deploying them... Before actually needing them. Nevertheless if you depend on any external crates you have to have access to them, even if only by referencing a local path.
- Cogitri 7y agoSee cargo-vendor for offline functionality
- asdkhadsj 7y agoYou can define local path or remote git repos as dependencies if you like. That does involve Cargo of course, but if you choose it should theoretically not leave your firewall. Also, you can run a local copy of all the documentation in all the repos pretty easily too. Huge asterisk: I've never tested any phone-homes, if that is what you're worried about. But, it can be pretty offline-friendly.
- sanxiyn 7y agoYou can work completely offline. All official tools support it. Rust team can't do much about ecosystem though. There are some libraries which download resource (say, large data table) over the network at build time. I consider these bugs, but maintainers of those libraries may disagree.
- afureta 7y agoGot any examples? I have some spare time and I'd like to improve that situation.
- sanxiyn 7y agohttps://www.reddit.com/r/rust/comments/bki8yo/warning_exists_in_the_security_risk_of_crate/ https://www.reddit.com/r/rust/comments/bki8yo/warning_exists... was one recent case.
- deleted 7y ago[deleted]
- codetrotter 7y ago> is there a sustainable way of working/developing with Rust while completely offline? Yes. Once you have downloaded your dependencies the first time while online you are able to work with them completely offline. > read documentation Rust docs: rustup downloads docs for Rust itself alongside the toolchain when you download it. `rustup doc --book` will open the locally downloaded copy of the book The Rust Programming Language in your browser. `rustup doc` will open the locally downloaded copy of the overview of Rust Documentation in your browser. The locally downloaded docs include things like the docs for the Rust Standard Library. Project and dependencies docs: `cargo doc --open' will build the docs for your project and for your dependencies as offline HTML files and open the locally build docs in your web browser for you. Subsequently running the same command while offline will open the already built docs in your web browser again. You will find the built docs under target/doc/ in your project. This includes the docs for your dependencies and their dependencies and so on. And even if you delete the built docs, for example by running `cargo clean', cargo can rebuild the docs offline because it has cached the source code of your dependencies and their dependencies and so on. > manually import libraries (downloaded manually, no dependency hell) Rather than attempt to do it manually I would advice that you run `cargo build' once while online, so that your dependencies are fetched and made available offline. Attempting to do it completely manually has no benefit that I can see and would only serve to waste time and probably introduce problems that would not happen if you leave it to cargo to fetch it all for you. And you can write crates of your own locally, never publish them online and import them by relative local path.
- jakobdabo 7y agoThank your for the detailed answer. > Attempting to do it completely manually has no benefit that I can see Package managers and build tools can do basically whatever they want - run commands, execute binaries, download data, upload data, send telemetry - whatever any one of the package maintainers wants. I prefer to develop in an offline VM. When a new library is required I just download it using the host machine, copy into VM and use it there. It's easy with make/cMake.
- gfs 7y ago
- jstrong 7y agocoming from rust - I spent three hours last night trying to build scylla (and failed). problem after problem, baffling errors, etc. -- what I would consider dependency hell. have you tried cargo? I'm actually curious what your perspective is that you think of the c++ situation as preferable somehow.
- gorbot 7y agoOnce you have rustup installed, run ‘rustup doc’. You will get standard library documentation from disk as well as “the book” which introduces the core concepts Then, if using cargo which I totally would, run ‘cargo doc —open’ to see api documentation for your project as well as your projects dependencies both direct and indirect. All from disk!
- azov 7y agoIn addition to what's been said in other replies, there's also `cargo vendor` which can give you even more flexibility when working offline.
- steveklabnik 7y agoThis is also being upstreamed into cargo soon!
- kd5bjo 7y agoI generally prefer to use Make as my build system everywhere, so that I only have to learn the quirks of one system, and it’s easier to handle mixed-language projects. The documentation for using rustc directly is hard to find, but it’s quite possible to skip Cargo entirely. I’ve had no trouble using it mostly like a C compiler, but I have run into a couple of quirks I needed to work around: * I haven’t figured out how to get dependency information out of the compiler, so I had to write a likely-fragile script to grep the rust sources. * In any project, crates have a single, flat namespace. If you want to treat them like you would object files in a C project you’ll need some scheme to prevent name conflicts between subdirectories. The more rust-y thing is to use the module system to include anything that shouldn’t be visible at the top level of your hierarchy. Otherwise, it’s fairly similar to a traditional compiler: rustc main.rs -o my-program # compile an executable rustc main.rs --test -o ... # compile the test framework rustc --crate-type=rlib ... # make an rlib (roughly equivalent to .o) rustc --extern name=path/to/rlib ... # reference another crate (required during compilation)
- steveklabnik 7y agorustc's docs are here: https://doc.rust-lang.org/stable/rustc/ https://doc.rust-lang.org/stable/rustc/