Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

User-side library generator. #3538

Merged
merged 4 commits into from
Nov 4, 2019
Merged

User-side library generator. #3538

merged 4 commits into from
Nov 4, 2019

Conversation

olonho
Copy link
Contributor

@olonho olonho commented Nov 2, 2019

No description provided.

var target: String? = null
var index = 0
var saveTemps = false
while (index < args.size) {
Copy link
Contributor

Choose a reason for hiding this comment

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

kotlinx.cli?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe.

ArgType.String, "output-directory", "o", "Output directory").required()
val target by argParser.option(
ArgType.String, "target", "t", "Compilation target").required()
val saveTemps by argParser.argument(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why argument, not option ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Option has value, argument - does not.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO in this case a lot more convenient is optional option --save-temps
If present - save, if not - delete.

Copy link
Contributor

@ilmat192 ilmat192 Nov 4, 2019

Choose a reason for hiding this comment

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

As far as I understand, argument is something passed without a flag at all. So currently the tools saves temporary data if the following args are passed:

./generate-platform  ... --target macos_x64 true

Copy link
Contributor

Choose a reason for hiding this comment

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

For me it works as generate-platform ... --target mingw save-temps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, reworked here a bit, indeed boolean option seems to be better fit.

fun dependsOn(defFile: DefFile): Boolean {
if (defFile == this) return true
for (dependency in this.depends) {
if (defFile.dependsOn(dependency)) return true
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be dependency.dependsOn(defFile)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually not needed anyway.

@olonho olonho merged commit e9a2319 into master Nov 4, 2019
@olonho olonho deleted the user_gen_libs branch November 4, 2019 12:13
olonho added a commit that referenced this pull request Nov 4, 2019
olonho added a commit that referenced this pull request Nov 4, 2019
destinationDir distDir

from(project("platformLibs").file("src/platform")) {
into('klib/platformDef')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Abuses klib directory. Maybe konan/platformDef or konan/targets/$target/platformDef?

@@ -472,6 +481,7 @@ task bundle(type: (isWindows()) ? Zip : Tar) {
}

task bundleRestricted(type: Tar) {
dependsOn("distDef")
Copy link
Collaborator

Choose a reason for hiding this comment

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

So bundle doesn't include these files on non-Apple hosts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, was unsure here as well. Added to bundle dependency.


from(project("platformLibs").file("src/platform")) {
into('klib/platformDef')
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are .sh scripts included intentionally? I don't expect these to work properly.

private class DefFile(val name: String, val depends: MutableList<DefFile>) {

override fun hashCode(): Int {
return name.hashCode()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not rely on identity-based equals/hashCode? Do you expect multiple DefFile objects for the same .def-file?
That would seem wrong, considering that there is mutable state in DefFile.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it was mostly for clearness of intentions.

while (markBlack.size < defFiles.size) {
visit(defFiles[index++])
}
return result
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it actually a reverse topological order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends on what we believe to be an order, I guess. First goes ones with least deps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Exactly. And in topological order first element has no dependencies on it.

// Now run interop tool on toposorted dependencies.
sorted.forEach { def ->
executorPool.execute {
// A bit ugly, we just block here until all dependencies are built.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use ForkJoinPool instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there's big difference here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would help to make this code more simple and avoid blocking threads with tasks that aren't ready to start.

"-target", target,
"-def", file.absolutePath,
"-compiler-option", "-fmodules-cache-path=$outputDirectory/clangModulesCache",
"-repo", "${outputDirectory.absolutePath}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one is likely not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was needed for me, otherwise indirect dependencies were not resolved.

"-no-default-libs", "-no-endorsed-libs", "-Xpurge-user-libs",
*def.depends.flatMap { listOf("-l", "$outputDirectory/${it.name}") }.toTypedArray())
println("Processing ${def.name}...")
K2Native.mainNoExit(invokeInterop("native", args))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use

fun daemonMain(args: Array<String>) = mainImpl(args, ::konancMainNoExit)
instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way it's more clear, wrt intentions afterward.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This way it requires more maintenance. I believe that calling the entry point of cinterop tool is clear enough.

intentions afterward.

Which ones?

// A bit ugly, we just block here until all dependencies are built.
while (def.depends.any { built[it] == 0 }) {
Thread.sleep(100)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't it hang if a dependency is failed to build?

olonho added a commit that referenced this pull request Nov 5, 2019
olonho added a commit that referenced this pull request Nov 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants