-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add androidNative targets. #1739
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
Open
MohammedKHC
wants to merge
11
commits into
square:master
Choose a base branch
from
MohammedKHC:android-native
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9700d24
Add androidNative targets.
MohammedKHC 1245ccf
Make Android Native a child of Linux.
MohammedKHC 6a1fca7
Add Android Native support for opendir/readdir/closedir.
MohammedKHC 8aabd6d
Add `PosixDirectory` and use it instead of expect/actual `DIR` functi…
MohammedKHC 44019d6
Use value class for `PosixDirectory`.
MohammedKHC af7e940
Merge branch 'master' of github.com:square/okio into android-native
MohammedKHC 307b25d
Use statx on Android native.
MohammedKHC d2f8421
Inline openPosixDirectory
MohammedKHC 53cf96b
Merge branch 'master' into android-native
MohammedKHC dfef416
Fix statx syscall for arm32
MohammedKHC 6348225
Merge branch 'master' into android-native
MohammedKHC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
okio/src/androidNativeMain/kotlin/okio/internal/PosixDirectory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (C) 2026 Square, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package okio.internal | ||
|
|
||
| import kotlinx.cinterop.COpaquePointer | ||
| import kotlinx.cinterop.reinterpret | ||
| import okio.Closeable | ||
| import okio.Path | ||
| import platform.posix.closedir | ||
| import platform.posix.opendir | ||
| import platform.posix.readdir | ||
|
|
||
| internal actual value class PosixDirectory(private val dir: COpaquePointer) : Closeable { | ||
| actual fun nextEntry() = readdir(dir.reinterpret()) | ||
| actual override fun close() { | ||
| closedir(dir.reinterpret()) // Ignore errno from closedir. | ||
| } | ||
| } | ||
|
|
||
| @Suppress("NOTHING_TO_INLINE") | ||
| internal actual inline fun openPosixDirectory(path: Path): PosixDirectory? { | ||
| return opendir(path.toString())?.let(::PosixDirectory) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
okio/src/nativeMain/kotlin/okio/internal/PosixDirectory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright (C) 2026 Square, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package okio.internal | ||
|
|
||
| import kotlinx.cinterop.COpaquePointer | ||
| import kotlinx.cinterop.CPointer | ||
| import okio.Closeable | ||
| import okio.Path | ||
| import platform.posix.dirent | ||
|
|
||
| /** | ||
| * `platform.posix.DIR` is not available on Android Native, so the standard | ||
| * POSIX directory APIs (`opendir`, `readdir`, `closedir`) cannot be used | ||
| * directly. | ||
| * | ||
| * [PosixDirectory] provides platform-specific implementation | ||
| * for `DIR`-related functionality. | ||
| */ | ||
| internal expect value class PosixDirectory(private val dir: COpaquePointer) : Closeable { | ||
| fun nextEntry(): CPointer<dirent>? | ||
| override fun close() | ||
| } | ||
|
|
||
| internal expect fun openPosixDirectory(path: Path): PosixDirectory? | ||
36 changes: 36 additions & 0 deletions
36
okio/src/nativeNonAndroidMain/kotlin/okio/internal/PosixDirectory.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (C) 2026 Square, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package okio.internal | ||
|
|
||
| import kotlinx.cinterop.COpaquePointer | ||
| import kotlinx.cinterop.reinterpret | ||
| import okio.Closeable | ||
| import okio.Path | ||
| import platform.posix.closedir | ||
| import platform.posix.opendir | ||
| import platform.posix.readdir | ||
|
|
||
| internal actual value class PosixDirectory(private val dir: COpaquePointer) : Closeable { | ||
| actual fun nextEntry() = readdir(dir.reinterpret()) | ||
| actual override fun close() { | ||
| closedir(dir.reinterpret()) // Ignore errno from closedir. | ||
| } | ||
| } | ||
|
|
||
| @Suppress("NOTHING_TO_INLINE") | ||
| internal actual inline fun openPosixDirectory(path: Path): PosixDirectory? { | ||
| return opendir(path.toString())?.let(::PosixDirectory) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the cleanest working approach so far.
I probably should’ve marked this PR as a draft from the beginning…
Man, everything feels way more complicated than it needs to be.
Why doesn’t platform.posix just expose DIR on Android?!
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.
Seems like these should all be
value classes to avoid the memory allocation. Does anything prevent that?Uh oh!
There was an error while loading. Please reload this page.
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.
@JakeWharton
The problem is that the actual implementation needs to store
And if you meant that the value should be DIR. Then this is kinda complicated.
as we cannot use expect/actual for DIR in only two source sets. (androidNative, nativeNonAndroid)
that's because this code will not compile under nativeNonAndroid
It will fail with an error cannot create a typealias to a typealias.
As platform.posix.DIR is a typealias on Linux.
we could create a new nativeNonLinux source set that will exclude androidNative and linux.
What do you think?
EDIT: I just realized that we could do this
and
Does this seem good?
And also we can make
openPosixDirectoryinline.Do you think it's worth it?
And btw, I really hate the Kotlin compiler advising me to not use inline on functions..
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.
@JakeWharton @swankjesse ?