-
Notifications
You must be signed in to change notification settings - Fork 52
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 Windows implementations. #45
base: master
Are you sure you want to change the base?
Conversation
Can someone please review it? |
oh god, I'm so sorry, I wanted to enable the windows CI on your branch, but I accidentally pushed some changes from my other branch, I'll try to have that sorted out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that generally this PR is very sound and well-made, good job!
But, before merging there are a couple of things to sort out:
- We need to resolve the issue with symlinking the assets directory, as discussed here
- One it's done I'd be nice to test the basic commands like
cargo mobile init
,cargo mobile build
,cargo mobile open
etc. across all supported platforms, because there are changes in this PR that indirectly affect Linux and Mac as well - Update the README (add Windows to supported platforms and mention any Windows' specific caveats like
cargo mobile update
failing)
On Windows, Path::join may makes invalid UNC path. It was fixed on nightly (rust-lang/rust#89270), but not yet on stable.
I think I've solved the problem of symbolic links. In addition, I fixed a path problem in stable that I missed using nightly. I've confirmed that the commands work on Windows except |
Once again, thank you so much for your contribution! @francesca64 may I kindly ask you to take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to merge this but I encountered a weird behaviour when testing on this branch now...
When I run cargo mobile init
for the first time the project is created successfully. However, if I do it the second time, I get the following error:
ln: failed to create symbolic link '/home/radek/code/cargo-mobile-sandbox/a/gen/android/a/app/src/main/assets': No such file or directory
error: Asset dir couldn't be symlinked into Android project
Failed to create a symbolic link from "../../../../../../assets" to directory "/home/radek/code/cargo-mobile-sandbox/a/gen/android/a/app/src/main/" (file and directory clobbering enabled): `ln` command failed: Command
"ln -n -s -f ../../../../../../assets /home/radek/code/cargo-mobile-sandbox/a/gen/android/a/app/src/main/assets" didn't complete successfully, exiting with code 1.
and the gen/android/a/app/src/main
directory appears to be missing.
When I then run cargo mobile init
again, the project is initialized successfully.
Basically, this behaviour alternates and it needs to be fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making such a massive contribution!
(and thanks to @zeerooth for thoroughly reviewing it!)
&mut len as _, | ||
) | ||
}?; | ||
return Ok(command); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Ok(command); | |
Ok(command) |
} | ||
Component::CurDir => {} | ||
Component::ParentDir => { | ||
if let Some(_) = buf.last() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if let Some(_) = buf.last() { | |
if let buf.last().is_some() { |
// %~dp0 will expand to C:\Users\MyHome\foo in code.cmd, which is completely broken. | ||
// Running it through powershell.exe does not have this problem. | ||
pub fn code_command() -> bossy::Command { | ||
bossy::Command::impure("powershell.exe").with_args(&["-Command", "code"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bossy::Command::impure("powershell.exe").with_args(&["-Command", "code"]) | |
bossy::Command::impure_parse("powershell.exe -Command code") |
|
||
pub fn command_path(name: &str) -> bossy::Result<bossy::Output> { | ||
bossy::Command::impure("where.exe") | ||
.add_arg(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.add_arg(name) | |
.with_arg(name) |
.expect("failed to getAndroid Studio uninstaller's parent path") | ||
.join(STUDIO_EXE_PATH); | ||
bossy::Command::impure(application_path) | ||
.add_arg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.add_arg( | |
.with_arg( |
) | ||
}); | ||
if handle.is_invalid() { | ||
return Err(runtime::Error::from_win32()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can drop the return
keyword and use else
to return the Ok(())
below.
err => Err(err), | ||
})?; | ||
let argv: Vec<_> = NativeArgv::new(&editor_command).into(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extraneous newline
|
||
impl Application { | ||
pub fn detect_editor() -> Result<Self, DetectEditorError> { | ||
let editor_command = Self::detect_associated_command(RUST_EXT).or_else(|e| match e { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename e
to err
and the current err
arm to _
.map(|arg| Self::replace_command_arg(arg, &path.as_ref().as_os_str())) | ||
.collect::<Vec<_>>(); | ||
bossy::Command::impure(&self.argv[0]) | ||
.add_args(&args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.add_args(&args) | |
.with_args(&args) |
|
||
#[derive(Debug, Error)] | ||
pub enum DetectEditorError { | ||
#[error("No default editor is set: AssocQueryStringW for \".rs\" and \".txt\" both failed")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error text needs to be a high-level user-friendly description that doesn't i.e. mention function names (while still being unambiguous enough that a developer can find the source)
If there is any work needed for this PR to be merged, I'd be glad to help (ofc, If the author of this PR gives me permissions to, or if he is inactive, I could create a new PR that is build on top of this PR and keep his commits in the new PR) |
The following points should be noted:
cargo mobile update
has not been tested, but it will probably fail on Windows because the running binary cannot be overwritten.