Paul Molodowitch
Paul Molodowitch

Reputation: 1446

What's the best way to use Cargo to build for multiple platforms using the same source directory?

I frequently flip between my desktop and laptop, which have different operating systems. To coordinate, I like to keep my development / project directories stored in Dropbox.

Cargo will try to build to the same directory (i.e. target/debug) from both operating systems. Ideally, I want a way that would allow me to automatically build to platform-specific build directories on each platform:

...or something similar.

Upvotes: 4

Views: 2342

Answers (2)

Paul Molodowitch
Paul Molodowitch

Reputation: 1446

I accepted Matthieu M.'s suggestion because it was elegant, functional, and made use of Cargo's features... but I realized that it didn't apply to my situation, where I wanted to sync between Mac and Windows, because Windows paths always start with, ie, "C:".

Also, I realized there's another easy way to solve this problem although it's Dropbox-specific:

Dropbox has a way to set files to be ignored, using file-system specific alternate streams / attributes. Details can be found here:

https://help.dropbox.com/en-US/files-folders/restore-delete/ignored-files

(Note: I formerly recommended using Dropbox's "selective sync" feature, to disable syncing of the target directory, but they changed the way this works, so that you can't have a directory with the same name as your "selective sync" directory.)

Upvotes: 2

Matthieu M.
Matthieu M.

Reputation: 299730

I would recommend looking at out-of-tree builds.

If you have a project such as:

project/
    Cargo.toml

You can add a .cargo directory:

project/
    .cargo/
        config
    Cargo.toml

And put the following into the config file:

[build]
target-dir = "/tmp/build/dir"

As long as the path is valid for both operating systems, then each will point to a local build.

Plus... you'll avoid syncing MBs/GBs of binaries to your Dropbox account.

Upvotes: 6

Related Questions