Non UI code lives in a static/shared lib that gets called from UI code. The non-UI code shouldn’t be coupled to a UI at all, instead reporting progress/completion via callbacks or other notification mechanisms.
If you must run on every platform for whatever reason, there is Rust, C, C# (Xamarin), etc.