A couple of development environment questions

...from a C programmer.
I have a small side-project which appears to be a good candidate to let me get familiar with Rust. However, schedule is tight and I can't change my programming environment; if I can "shoehorn" Rust compiling and building into my existing "workshop" I can do it, if not I'll have to wait for another opportunity.

  1. All my source code lives in a directory that is read/write only when the code is being editing, when it is compiled, linked and tested it is read-only. Can rust compiler and linker operate in such environment?

  2. In this instance any "version control" automatism is an unwelcome complication. Can I completely by-pass the necessity to deal with it in Rust/Cargo?

  3. While I can do what is necessary to copy required components from the Internet to set up the development environment, while coding and testing I am on a local network only,, without Internet access on the development machine. Is this likely to present a problem?

  4. For a simple statically linked command-line Linux executable, are there any Rust-related run-time files required to be passed on to the user of the program?


Yes, you can set CARGO_TARGET_DIR in the environment (or [build] target-dir in the config file) to tell the build system to put all compiled/generated artifacts in some location outside of the source directory.

The index for the crates.io registry lives in a git repo. Cargo uses libgit2 internally to fetch and update this index. After initially fetching the index, you can use the --offline flag to tell Cargo not to auto-update it when your manifest changes.

The crates.io registry uses GitHub for authentication. If you want to publish packages on this registry, you must have a GitHub account.

There are also a few optional integration points:

  • The cargo new command will initialize a git repo and create a .gitignore file by default. Use cargo new --vcs none to disable this.

  • Cargo allows you to use git repos as dependencies. If you don't keep your dependencies in git, you can instead use a package registry or the local filesystem.

See “How can Cargo work offline?” and/or the cargo vendor command.

Also useful: The rustup doc command will open the locally-installed standard library and toolchain documentation, and the cargo doc --open command will build and then open locally-stored API docs for your own project and all of its dependencies.


In addition to all of the Cargo options @mbrubeck mentioned, it’s also possible to invoke rustc directly. You give up the crates ecosystem, but it behaves like a C compiler: it reads the source code and produces a binary; nothing else.

1 Like

Thanks for the responses.

Indeed, :

Seems close to the nirvana I desire. :slight_smile:

I have a bunch of C language thread-safe functions (500-800 lines of clean C code) in a library which I must either port to Rust or statically link with the main program. My next step is to decide which of the two options will work better: that C code is now quite stable, operate on concise floting-point and integer structures. There would be no advantage in porting it if including them as a C library in the Rust program presents no problem. Comments are appreciated.

Working with and linking to C libraries is fairly straightforward. The Rustnomicon has a good overview:


(Side note: the libc crate in the example is optional; it’s just importing type aliases for readability)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.