mozilla / rust-android-gradle

Apache License 2.0
1.03k stars 67 forks source link

WSL Support #34

Closed OliverCulleyDeLange closed 4 years ago

OliverCulleyDeLange commented 4 years ago

Im on windows and have inherited a rust library that only builds via WSL at the moment, and before we invest time into getting it building on Windows, i thought i'd see if i can run cargo via WSL usin this plugin. I had a stab, but didn't get very far.

With rust.cargoCommand set in local.properties, you can set the first portion of the command eg cargo, however the only way i've found of running cargo build via WSL is C:\Windows\System32\bash.exe --login -c "cd /mnt/c/Users/path/to/rust/code/ && cargo build --verbose --release --target=armv7-linux-androideabi" - Which requires an extra " at the end...

I've tried other approaches like C:\Windows\System32\wsl.exe -- (cd /mnt/c/Users/path/to/rust/code/; ~/.cargo/bin/cargo build --verbose --release --target=armv7-linux-androideabi) but this also requires appending a ) to the end of the command.

I'd like to find a way to call cargo via WSL using the right working directory and login shell.

I know this is probably more of a WSL issue - but was wondering if there anything that could be done in the plugin to make life easier with WSL.

ncalexan commented 4 years ago

@OliverCulleyDeLange hmm, interesting problem. Generally, such shenanigans are arranged by making a "fake" cargo.bat or whatever, and having that do the argument manipulations. But that might be hard. Can you investigate setting rust.cargoCommand to some batch file, and see if it gets invoked? Then you can do whatever you need.

If there are blockers to having that work (maybe we don't invoke batch files correctly on Windows?), then let's hammer those out, perhaps with special handling of scripts on Windows.

OliverCulleyDeLange commented 4 years ago

@ncalexan Thanks for pointing me in the right direction. I made a batch script, pointed to it using rust.cargoCommand and it seems to work.

:: File: cargo-wsl.bat
:: rust.cargoCommand=C\:\\path\\to\\cargo-wsl.bat
ECHO OFF
echo CARGO ARGS: %*
C:\Windows\System32\wsl.exe -- bash -cl "cargo %*"

Looks like my previous attempts weren't working as the gradle exec wants a single file to execute, not a string command. _o_/