rust-windowing / rust-windowing/winit

Make main thread check adjustible in case of jna lib

Open
#4,099 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

DS - wayland S - enhancement
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

Description

Hi there,
I have this use case:

transitive winit dependency in a rust library, consumed by my cdylib libexample.so.

This exports uniffi bindings for Kotlin.

Consuming Kotlin project is console or Swing application, but let's stick here on example console app with no other UI parts, except rust windowing.

libexample.so is loaded with jna.

OS is Ubuntu/Linux with openjdk.

Unfortunately, even no threading or coroutines are involved on no side, the native lib runs always in a second, consecutive thread having always a 3 numbers higher pid/tid than the main thread.
Here we talk about two java os-threads.

Therefore os thread checking like if(rustix:🧵:id == rustix::process::id) will fail.

For my Kotlin Application everything runs on the java main thread.

Meanwhile I patched the winit crate locally and just return true in is_main_thread().
Everything runs smooth with that hack.

My question is: Can we consider above usecases somehow?
Can we have a feature or other Cargo.toml configuration option to circumvent other solutions like EventloopBuilder/extension/hooks (with_any_thread)?

The thing is, I want to be agnostic of wayland or whatever target and just want to use transitive code or examples as provided.

Thank you so much for your help and understanding!

P.S.: On which platforms is this feature relevant?
I would suggest to put "Linux" and "Jna/Jni" in the list.
I find the mechanism/use case is similar to Android architecture, but... It's not Android.

Relevant platforms

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with winit's is_main_thread() check and trace how it is reached for Linux targets. Review EventloopBuilder, extension hooks such as with_any_thread, and the Cargo.toml feature options in the context of a Rust cdylib loaded by Kotlin/JNA on Ubuntu. Done means the supported configuration and its platform behavior are defined, with coverage for the requested use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, linux, rust
Domain
desktop, operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.