Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@leodouglas
Copy link

No description provided.

@leodouglas leodouglas changed the title cinterop support C interop build integration support Nov 14, 2025
@joffrey-bion joffrey-bion requested a review from Jeffset November 14, 2025 10:27
@joffrey-bion
Copy link
Collaborator

Hey! I'd like to thank you again for the effort and the reactivity. I'm not using a lot of sugar in my PR comments, so if something sounds harsh or direct at first glance, please read the text while imagining a gentle and polite tone 😄

I haven't finished reviewing by any means, but I figured it was worth doing a first pass quickly.

@joffrey-bion joffrey-bion self-requested a review November 17, 2025 14:16
Copy link
Collaborator

@joffrey-bion joffrey-bion 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 your updates! Here is another pass. Sorry for the delay, but also let's wait for @Jeffset to be back from vacation (end of January)


@SchemaDoc("C/Objective-C interop settings for native targets")
val cinterop: CinteropSettings by nested()
val cinterop: Map<String, CinteropModule> by value(default = emptyMap())
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are the keys in this map used for? If they don't serve any purpose from the user's perspective, I think we should just make this a list.

Copy link
Author

@leodouglas leodouglas Jan 25, 2026

Choose a reason for hiding this comment

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

Hey @joffrey-bion, the original idea was to follow the pattern proposed in the Kotlin/Native documentation, where each cinterops declaration has its own alias, for example:

cinterops {
    val libcurl by creating {
        definitionFile.set(project.file("src/nativeInterop/cinterop/libcurl.def"))
        packageName("com.jetbrains.handson.http")
        compilerOpts("-I/path")
        includeDirs.allHeaders("path")
    }
}
cinterop:
  hello:
    defFile: 'src/nativeInterop/cinterop/libcurl.def'

In that model, using a map makes sense to allow identification by name.

That said, since this alias is not currently used anywhere, I agree there’s no practical benefit from the user’s perspective. We can simplify this and switch to a list.

Comment on lines +34 to +39
try {
cinteropDir.children.filter { it.name.endsWith(".def") }
} catch (e: IOException) {
// Log error?
emptyList()
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this piece of code can actually throw IOException. Could you please explain why we try/catch here?

To be honest, I wouldn't actually try to catch anything, even if it could throw (just like in the if right above). If we can't read files properly, we don't want to hide the error, it's better to let it fail. The consumer of the frontend code will decide what to do with exceptions anyway.

.singleLeafFragment()

val cinteropTasks = fragment.settings.native?.cinterop?.map { (moduleName, cinteropModule) ->
val defFile = cinteropModule.defFile ?: "resources/cinterop/$moduleName.def"
Copy link
Collaborator

Choose a reason for hiding this comment

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

The cinterop definitions might need their own dir instead of resources. In gradle, the default is src/nativeInterop/cinterop/{name_of_the_cinterop}.def. Since we don't use the same src/main/ convention, the src/nativeInterop/cinterop dir from Gradle could be mapped to nativeInterop/cinterop or just cinterop directly under the root of the module in Amper.

Regarding the filename, maybe we should use the name of the interop lib (the key in the settings.cinterops map) instead of the module name. That would give meaning to that key, so it needs to be discussed.

Also, ideally this default value should be set on the frontend side, as a computed value from the interop lib name. @Jeffset will probably be able to shed some light on how to do this properly (or reply that it's not possible yet 😆).

@leodouglas
Copy link
Author

Thanks for your updates! Here is another pass. Sorry for the delay, but also let's wait for @Jeffset to be back from vacation (end of January)

Sure, @joffrey-bion, np

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.

2 participants