Skip to content

Fix #30#31

Open
Mygod wants to merge 1 commit into
mozilla:masterfrom
Mygod:patch-1
Open

Fix #30#31
Mygod wants to merge 1 commit into
mozilla:masterfrom
Mygod:patch-1

Conversation

@Mygod

@Mygod Mygod commented Apr 24, 2020

Copy link
Copy Markdown
Contributor

Mygod referenced this pull request in shadowsocks/shadowsocks-android Apr 24, 2020

@thomcc thomcc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hrmmm... I think this is wrong if you're outputing for the current platform. We go through some effort to ensure that we don't pass the target arg to reuse as much of the existing build output.

@Mygod

Mygod commented Apr 24, 2020

Copy link
Copy Markdown
Contributor Author

What do you mean by "current platform?"

@thomcc

thomcc commented Apr 24, 2020

Copy link
Copy Markdown
Contributor

I'm going to have to do some testing on this. Also I'm not fully sure I understand the issue...

@thomcc

thomcc commented Apr 24, 2020

Copy link
Copy Markdown
Contributor

I mean that this doesn't work with the fix we have in place for #10.

Edit for clarification: target/$toolchain/$profile/... is wrong if you're on e.g. macos and doing a build for macos desktop, it would just be target/$profile/....

@thomcc

thomcc commented Apr 24, 2020

Copy link
Copy Markdown
Contributor

Sorry, my bad, I just realized this code is inside a branch that only runs for non-desktop builds. It probably still applies but I'm not really worried about people building android apps on android.

That said, I'll still need to do some testing of it before I cut a release.

@Mygod

Mygod commented Apr 24, 2020

Copy link
Copy Markdown
Contributor Author

Fixed.

@Mygod

Mygod commented Apr 27, 2020

Copy link
Copy Markdown
Contributor Author

No further comments?

@thomcc

thomcc commented Apr 27, 2020

Copy link
Copy Markdown
Contributor

Sorry, I’ve been sick, and I need to find time to test, probably later this week. I’d also like to better understand the motivation here.

@Mygod

Mygod commented Apr 28, 2020

Copy link
Copy Markdown
Contributor Author

The workaround is from rust-lang/cargo#1706 (comment), the soname flags did not seem to work for us.

File(project.rootProject.buildDir, "linker-wrapper/linker-wrapper.py").path)
environment("RUST_ANDROID_GRADLE_CC", cc)
environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-Wl,-soname,lib${cargoExtension.libname!!}.so")
environment("RUST_ANDROID_GRADLE_CC_LINK_ARG", "-o,$cargoOutputDir/lib${cargoExtension.libname!!}.so")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, I wonder if we should be still setting the soname in addition to this. Do you know if the current version still ends up with the correct soname?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure.

@Mygod

Mygod commented May 5, 2020

Copy link
Copy Markdown
Contributor Author

The new patch should fix things in a simpler way. Not sure why you would want to compile non-Android binaries with this plugin though.

@ncalexan

ncalexan commented May 5, 2020

Copy link
Copy Markdown
Member

The new patch should fix things in a simpler way. Not sure why you would want to compile non-Android binaries with this plugin though.

We compile the same code for Desktop platforms to run unit tests against it -- it's really nice :)

@thomcc

thomcc commented May 5, 2020

Copy link
Copy Markdown
Contributor

I'll test this out (and cut a release assuming it works) later today or tomorrow, sorry for the delay here (I was sick, but am not anymore).

@Mygod

Mygod commented May 5, 2020

Copy link
Copy Markdown
Contributor Author

Alright but if the unit tests are written in rust, probably there is no need to bundle them into apk so I guess my patch still makes sense. :)

spec.include("lib${libname}.dylib")
spec.include("${libname}.dll")
spec.include(libname!!)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Huh, is this right for non-linux platforms? macos uses .dylib and windows uses .dll.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh maybe the issue is that I am compiling a binary to be bundled into the apk -- not a library.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, for bundling an APK that's right, but rust-android-gradle also supports being used for other situations (namely unit tests on the host machine, as discussed in comments below).

Sorry for all the trouble here!

@thomcc

thomcc commented May 5, 2020

Copy link
Copy Markdown
Contributor

Alright but if the unit tests are written in rust

@ncalexan meant android unit tests. Example: https://github.com/mozilla/application-services/blob/master/components/logins/android/src/test/java/mozilla/appservices/logins/DatabaseLoginsStorageTest.kt is testing the rust code in this crate https://github.com/mozilla/application-services/tree/master/components/logins and it "just works" and automatically builds the shared library for the current platform and runs it via robolectric.

@thomcc

thomcc commented May 5, 2020

Copy link
Copy Markdown
Contributor

Yes, this doesn't work for local unit tests. I'll update the code to the sample project in this repository that demonstrates this so that you can test against that.

Again, sorry for all the issues here.

@ncalexan

Copy link
Copy Markdown
Member

@Mygod I saw email from you a few days ago, but now I can't find the comment on GH.

I can't really tell what the issue you are trying to solve is. If I understand correctly, you are trying to put a Rust binary executable into an Android APK, and then to run that executable on a device? I have a spare half hour, I'll try to see if that can be done already.

@Mygod

Mygod commented Aug 13, 2021

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants