Skip to content
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

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

kazatsuyu
Copy link

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.
  • Use hard links for libraries under jniLibs since symbolic links cannot be created, and simply copy them if they fail.
  • Instead of symbolic links for assets directory, copy them at Gradle build time.

@kazatsuyu
Copy link
Author

Can someone please review it?

@zeerooth
Copy link
Contributor

zeerooth commented Nov 3, 2021

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

src/os/macos/mod.rs Outdated Show resolved Hide resolved
src/os/windows/mod.rs Outdated Show resolved Hide resolved
@zeerooth zeerooth added host: Windows type: enhancement Wouldn't this be the coolest? labels Nov 3, 2021
@kazatsuyu kazatsuyu requested a review from zeerooth November 4, 2021 12:16
Copy link
Contributor

@zeerooth zeerooth left a 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.
@kazatsuyu
Copy link
Author

kazatsuyu commented Nov 5, 2021

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 cargo update, but I haven't checked if there are no problems on Linux and macOS. (Of course, it would be better to have someone other than me test it on Windows as well.)

@kazatsuyu kazatsuyu requested a review from zeerooth November 5, 2021 13:18
src/env.rs Outdated Show resolved Hide resolved
zeerooth
zeerooth previously approved these changes Nov 29, 2021
@zeerooth
Copy link
Contributor

Once again, thank you so much for your contribution!
I think that now this PR is ready to be merged - I've briefly tested the latest version on Linux and Mac, updated the README and approved it, but since the changes here are quite massive, I'd like someone else to take a look and approve as well.

@francesca64 may I kindly ask you to take a look?

@zeerooth zeerooth requested a review from francesca64 December 2, 2021 23:10
Copy link
Contributor

@zeerooth zeerooth left a 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.

@zeerooth zeerooth dismissed their stale review December 14, 2021 22:31

New changes are needed

Copy link
Contributor

@francesca64 francesca64 left a 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Ok(command);
Ok(command)

}
Component::CurDir => {}
Component::ParentDir => {
if let Some(_) = buf.last() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.add_arg(
.with_arg(

)
});
if handle.is_invalid() {
return Err(runtime::Error::from_win32());
Copy link
Contributor

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();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

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 {
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.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")]
Copy link
Contributor

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)

@amrbashir
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
host: Windows type: enhancement Wouldn't this be the coolest?
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants