Build Tauri for all platforms on M1
Asked Answered
M

2

5

Is there a way to build Windows and Linux versions of Tauri on my macbook pro m1? I already tried it with --target I just get an error while the build.

yarn run v1.22.15
$ tauri build -t x86_64-pc-windows-msvc
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.86
   Compiling libc v0.2.119
   Compiling cfg-if v1.0.0
   Compiling serde_derive v1.0.136
   Compiling serde v1.0.136
   Compiling ppv-lite86 v0.2.16
   Compiling siphasher v0.3.9
   Compiling getrandom v0.1.16
   Compiling winapi v0.3.9
error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-msvc` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-msvc`

error[E0463]: can't find crate for `compiler_builtins`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed
Error running CLI: failed to build app: Result of `cargo build` operation was unsuccessful: exit status: 101
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Mano answered 16/3, 2022 at 18:20 Comment(0)
M
6

According to the documents, to compile for all three os on a single machine is not supported, but can be done with VM's or Github Actions.

From the docs:

Cross-platform compilation is not supported at this moment. If you want to produce binaries for all three operating systems, you can use Virtual Machines or a CI service like GitHub Actions.

Mayramays answered 26/4, 2022 at 22:19 Comment(1)
I already fixed it with Github Actions.Mano
D
2

Just sharing our experience, as I've been getting back to this question over and over again:

We had success building for all platforms on a single mac m2 machine, while using docker (for linux) and UTM (for windows) to compile for other platfroms.

While it's not exactly what works with out of the box GitHub Actions, if you're to design your own build system and run it via GitHub Actions Runner, it will get you to build it on a single machine.

Another alternative that can be useful to optimize the build flow is to use workspaces so you won't have to rebuild parts of your app each time.

Ideally even distributing part of the business logic as a shared library (dylib or dll) so you can use cross-rs to cross compile for all platforms, and then just ship it as a part of your application bundle.

Mind that cross-rs works well for most of the code, except the cases where you need to use platform's APIs like winRT, win32 on windows or Cocoa on mac, etc.

Demivolt answered 19/1 at 21:59 Comment(1)
Nice. I love UTM for this reason.Mayramays

© 2022 - 2024 — McMap. All rights reserved.