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

update: first mapping tutorial revamp #4708

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danil-pavlov
Copy link
Contributor

No description provided.

@danil-pavlov danil-pavlov requested a review from a team as a code owner February 17, 2025 18:04
@daniCsorbaJB daniCsorbaJB self-requested a review February 20, 2025 09:01
Copy link
Contributor

@daniCsorbaJB daniCsorbaJB left a comment

Choose a reason for hiding this comment

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

Great addition - I left a couple of comments, please let me know what you think


Create a `lib.h` file to see how C functions are mapped into Kotlin:
There are the following [data types in the C programming language](https://en.wikipedia.org/wiki/C_data_types):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
There are the following [data types in the C programming language](https://en.wikipedia.org/wiki/C_data_types):
The C programming language has the following [data types](https://en.wikipedia.org/wiki/C_data_types):

Copy link
Contributor

Choose a reason for hiding this comment

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

Might not be the best because of the link anchor with this suggestion, but "There are the following data types" feels a bit awkward to me 🤔

#define LIB2_H_INCLUDED
* Basic types: `char, int, float, double` with modifiers `signed, unsigned, short, long`
* Structures, unions, arrays
* Structures, unions, arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate list element?


The best way to see what C data types are visible in Kotlin is to try it.
You can use the command line to generate a Kotlin library, either directly or with a script file (such as `.sh` or `.bat` file).
However, this approach doesn't scale well for big projects that have hundreds of files and libraries.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
However, this approach doesn't scale well for big projects that have hundreds of files and libraries.
However, this approach doesn't scale well for large projects that have hundreds of files and dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

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

it might be incorrect to say dependencies instead of libraries but if it's correct I feel like it could be more encompassing than saying libraries here (or perhaps we could say library dependencies?).

with big vs large projects - tbh both works I think large might be a bit more formal but that's it.

You can use the command line to generate a Kotlin library, either directly or with a script file (such as `.sh` or `.bat` file).
However, this approach doesn't scale well for big projects that have hundreds of files and libraries.
Using a build system simplifies the process by downloading and caching the Kotlin/Native
compiler binaries and libraries with transitive dependencies, and by running the compiler and tests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
compiler binaries and libraries with transitive dependencies, and by running the compiler and tests.
compiler binaries and libraries with transitive dependencies, as well as running the compiler and tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

might be a bit more of a smooth transition but the original is also fine I think

#define LIB2_H_INCLUDED
* Basic types: `char, int, float, double` with modifiers `signed, unsigned, short, long`
* Structures, unions, arrays
* Structures, unions, arrays
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Structures, unions, arrays

}
```
The project file configures the C interop as an additional build step.
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about all the different
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about all the different
Check out the [Multiplatform Gradle DSL reference](multiplatform-dsl-reference.md) to learn about the different

Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion)
it feels good to me even without it and a bit more concise


## Primitive types in kotlin
Let's see how C primitive types are mapped into Kotlin/Native and fix the example project.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Let's see how C primitive types are mapped into Kotlin/Native and fix the example project.
Let's see how C primitive types are mapped into Kotlin/Native and update the example project accordingly.

With the help of IntelliJ IDEA's __Go to | Declaration__ or
compiler errors, you see the following generated API for the C functions:
With the help of IntelliJ IDEA's [Go to declaration](https://www.jetbrains.com/help/rider/Navigation_and_Search__Go_to_Declaration.html)
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can see the following generated API for C functions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can see the following generated API for C functions:
command (<shortcut>Cmd + B</shortcut>/<shortcut>Ctrl + B</shortcut>), you can view the following generated API for C functions:


## Update Kotlin code

Now that you've seen C definitions, you can update Kotlin code. The final code in the `hello.kt` file may look like this:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Now that you've seen C definitions, you can update Kotlin code. The final code in the `hello.kt` file may look like this:
Now that you've seen the C definitions, you can update the Kotlin code. The final code in the `hello.kt` file may look like this:

}
```

## Next steps
To check that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
To check that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application)
To verify that everything works as expected, run the `linkDebugSharedNative` Gradle task [in IDE](native-get-started.md#build-and-run-the-application)

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