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 no-op JVM target #626

Merged
merged 15 commits into from
Feb 12, 2024

Conversation

konpach
Copy link
Contributor

@konpach konpach commented Jan 30, 2024

Relates Issue: #380

Context: Until library gets a proper implementation for jvm targets we want to allow the usage of the library in supported targets along with jvm. Currently is not possible to compile shared if jvm target exists (as there is no corresponding implementation in kable).
Solution: Provide an empty implementation that throws runtime exceptions for kable for jvm target.

@konpach konpach force-pushed the konpach/add-jvm-target-with-void-implem branch from 7d88b05 to dd9ad8c Compare January 30, 2024 18:22
@twyatt twyatt added the minor Changes that should bump the MINOR version number label Jan 30, 2024
@konpach konpach changed the title Add jvm target with void implementation to allow compilation along with supported targets Add jvm target with void implementation to allow compilation along with supported targets - Relates Issue: #380 Jan 30, 2024
@konpach konpach marked this pull request as ready for review January 30, 2024 18:25
@konpach konpach requested review from twyatt and a team as code owners January 30, 2024 18:25
@konpach konpach requested a review from sdonn3 January 30, 2024 18:25
@konpach
Copy link
Contributor Author

konpach commented Jan 30, 2024

Build failed due to

Expected folder with API declarations '/Users/runner/work/kable/kable/core/api/android' does not exist.
  Please ensure that ':apiDump' was executed in order to get API dump to compare the build against

I thought that these are generated during the build, will run locally and add.

@twyatt
Copy link
Member

twyatt commented Jan 30, 2024

This may have changed/improved, but I thought historically having a JVM and Android target in the same module would confuse Gradle on the consumer side?

In other words, would an Android app project be able to consume Kable if it had both an Android target and a (no-op) JVM target? How would it know to use the Android when both are available?

If you have a chance (if not, then I'll try to find some time) to test these changes in the SensorTag sample app to ensure it doesn't break Android app consumers.

If it does break Android consumers, then I believe we'll have to introduce a new -android suffixed artifact for Android consumers. 🤔

@konpach
Copy link
Contributor Author

konpach commented Jan 30, 2024

This may have changed/improved, but I thought historically having a JVM and Android target in the same module would confuse Gradle on the consumer side?

In other words, would an Android app project be able to consume Kable if it had both an Android target and a (no-op) JVM target? How would it know to use the Android when both are available?

TBH I haven't experienced this before. I thought it's handled by gradle. But good point

If you have a chance (if not, then I'll try to find some time) to test these changes in the SensorTag sample app to ensure it doesn't break Android app consumers.

If it does break Android consumers, then I believe we'll have to introduce a new -android suffixed artifact for Android consumers. 🤔

I tried it with SensorTag and it works as expected. Also, I tried it with a project that has iOS, android and desktop targets and it compiles and runs as expected for all of the platforms. After you comment I also did a sanity check with my android app that scanning and connecting to a BLE device works as before (without the no-op jvm impl).

@twyatt

@twyatt
Copy link
Member

twyatt commented Jan 30, 2024

Awesome! Thanks for testing/validating!

Copy link
Contributor

@cedrickcooke cedrickcooke left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Weighing in on the build issues re. having both jvm and android targets, I think I remember it being a problem specifically when there was a diamond hierarchy. If jvm-library depends on kable, android-library depends on kable, and your-android-app depends on both jvm-library and android-library, problems show up.

Supporting JVM doesn't automatically break anything so I'm cool with this going in, but it does leave some room to shoot yourself in the foot.

core/build.gradle.kts Outdated Show resolved Hide resolved
core/api/android/core.api Outdated Show resolved Hide resolved
core/src/androidMain/kotlin/Profile.kt Show resolved Hide resolved
@@ -0,0 +1,6 @@
package com.juul.kable

public fun jvmNotImplementedException(): Nothing = throw NotImplementedError(
Copy link
Member

Choose a reason for hiding this comment

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

Can this be internal?

Suggested change
public fun jvmNotImplementedException(): Nothing = throw NotImplementedError(
internal fun jvmNotImplementedException(): Nothing = throw NotImplementedError(

Copy link
Contributor Author

@konpach konpach Feb 3, 2024

Choose a reason for hiding this comment

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

No, if it's internal, the compiler gives error about the visibility.

Copy link
Member

Choose a reason for hiding this comment

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

I presume the error is related to other modules not being about to access it?

In that case, can we make it internal and duplicate the function in any module that uses it?

That way we aren't exposing a new function on the public API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Actually, I miss understood the error. It seemed relevant but actually it was hiding a missing impl in the exceptions module! Made this internal and also added the implementation for the jvm target for the IOException.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Saw your revert, makes sense, thank you. Don't know why building locally failed but passing here in GHA. Will try to understand.

konpach and others added 3 commits February 3, 2024 08:13
Co-authored-by: Travis Wyatt <travis.i.wyatt@gmail.com>
@konpach
Copy link
Contributor Author

konpach commented Feb 6, 2024

@twyatt anything more to look into?

@twyatt
Copy link
Member

twyatt commented Feb 7, 2024

Apologies for the delay.

Looks good aside from one last comment I left re: removing the exception function from the public API.

@twyatt twyatt changed the title Add jvm target with void implementation to allow compilation along with supported targets - Relates Issue: #380 Add no-op JVM target Feb 8, 2024
Copy link
Member

@twyatt twyatt left a comment

Choose a reason for hiding this comment

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

Looks great!
I'll do some final testing this weekend and get it merged/released.
Thanks @konpach!

@twyatt twyatt enabled auto-merge (squash) February 12, 2024 06:35
@twyatt twyatt merged commit c3c8adc into JuulLabs:main Feb 12, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Changes that should bump the MINOR version number
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants