<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.0">Jekyll</generator><link href="https://dev.brainiumstudios.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://dev.brainiumstudios.com/" rel="alternate" type="text/html" /><updated>2021-07-14T23:10:36+00:00</updated><id>https://dev.brainiumstudios.com/feed.xml</id><title type="html">Brainium Dev Blog</title><entry><title type="html">cargo-mobile: Rust on mobile made easy!</title><link href="https://dev.brainiumstudios.com/2020/11/24/cargo-mobile.html" rel="alternate" type="text/html" title="cargo-mobile: Rust on mobile made easy!" /><published>2020-11-24T18:00:00+00:00</published><updated>2020-11-24T18:00:00+00:00</updated><id>https://dev.brainiumstudios.com/2020/11/24/cargo-mobile</id><content type="html" xml:base="https://dev.brainiumstudios.com/2020/11/24/cargo-mobile.html">&lt;p&gt;&lt;strong&gt;&lt;em&gt;The answer to “how do I use Rust on iOS and Android?”&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For nearly 2 years, we’ve been perfecting a tool called &lt;a href=&quot;https://github.com/BrainiumLLC/cargo-mobile&quot;&gt;cargo-mobile&lt;/a&gt;. It’s a framework-agnostic tool that generates all the boilerplate of a Rust mobile project, and is packed full of handy commands for building and running on mobile devices.&lt;/p&gt;

&lt;p&gt;If you’d like to follow along, installation is easy:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;--git&lt;/span&gt; https://github.com/BrainiumLLC/cargo-mobile
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that cargo-mobile currently only works on macOS! If you shoot us a PR that adds support for Linux or Windows, we’ll shower you in heart emoji. Feel free to ask us for guidance if you’re interested!&lt;/p&gt;

&lt;p&gt;Additionally, until Rust 1.49.0 is released, you can’t build for iOS unless you’re using &lt;a href=&quot;https://github.com/BrainiumLLC/cargo-mobile#status&quot;&gt;the current beta&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To start a new project, you just need to run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cargo mobile init&lt;/code&gt;:&lt;/p&gt;

&lt;figure class=&quot;terminal&quot;&gt;
    &lt;img alt=&quot;`cargo mobile init` demo&quot; src=&quot;/assets/cargo-mobile/init.svg&quot; /&gt;
&lt;/figure&gt;

&lt;p&gt;Just like that, you have a version of &lt;a href=&quot;https://bevyengine.org/&quot;&gt;Bevy&lt;/a&gt;’s &lt;a href=&quot;https://github.com/bevyengine/bevy/blob/master/examples/game/breakout.rs&quot;&gt;Breakout example&lt;/a&gt; that can run out of the box on desktop, iOS, and Android!&lt;/p&gt;

&lt;p&gt;As usual, you can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cargo run&lt;/code&gt; to run on desktop:&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;`cargo run` demo&quot; href=&quot;/assets/cargo-mobile/desktop.png&quot;&gt;
    &lt;img alt=&quot;`cargo run` demo&quot; title=&quot;`cargo run` demo&quot; src=&quot;/assets/cargo-mobile/desktop.png&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More excitingly, it’s easy to run on iOS and Android!&lt;/p&gt;

&lt;h2 id=&quot;ios&quot;&gt;&lt;a href=&quot;#ios&quot;&gt;iOS&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;We provide a convenience command for opening your project in Xcode:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo apple open
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;From there, you can build your project like you normally would in Xcode! Just hit that Play button. It’ll work on Simulator, too.&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;Xcode project&quot; href=&quot;/assets/cargo-mobile/xcode.png&quot;&gt;
    &lt;img alt=&quot;Xcode project&quot; title=&quot;Xcode project&quot; src=&quot;/assets/cargo-mobile/xcode.png&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can even set breakpoints!&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;Xcode breakpoints&quot; href=&quot;/assets/cargo-mobile/breakpoints.png&quot;&gt;
    &lt;img alt=&quot;Xcode breakpoints&quot; title=&quot;Xcode breakpoints&quot; src=&quot;/assets/cargo-mobile/breakpoints.png&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you’re not a fan of opening Xcode, you can also run directly from the command line. Be warned that the output might contain some spurious errors; we’re still improving that! Also, you can’t currently use Simulator unless you’re running from Xcode.&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo apple run
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Whether you run from Xcode or the command line, you should ultimately be greeted by Breakout:&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;Running on an iPhone XR&quot; href=&quot;/assets/cargo-mobile/iphone.jpg&quot;&gt;
    &lt;img alt=&quot;Running on an iPhone XR&quot; title=&quot;Running on an iPhone XR&quot; src=&quot;/assets/cargo-mobile/iphone.jpg&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We provide several other helpful iOS commands, which are listed in our help info:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo apple
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;android&quot;&gt;&lt;a href=&quot;#android&quot;&gt;Android&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Naturally, we also provide a convenience command for opening your project in Android Studio:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo android open
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once again, you just need to hit the Run button like you normally would.&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;Android Studio project&quot; href=&quot;/assets/cargo-mobile/android-studio.png&quot;&gt;
    &lt;img alt=&quot;Android Studio project&quot; title=&quot;Android Studio project&quot; src=&quot;/assets/cargo-mobile/android-studio.png&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alternatively, you can skip Android Studio and run directly from the command line:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo android run
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Either way, it should pop up on your connected device:&lt;/p&gt;

&lt;p&gt;&lt;a title=&quot;Running on a Pixel 4&quot; href=&quot;/assets/cargo-mobile/pixel.jpg&quot;&gt;
    &lt;img alt=&quot;Running on a Pixel 4&quot; title=&quot;Running on a Pixel 4&quot; src=&quot;/assets/cargo-mobile/pixel.jpg&quot; /&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more Android commands in our help info:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cargo android
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;going-forward&quot;&gt;&lt;a href=&quot;#going-forward&quot;&gt;Going forward&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Be advised that Bevy’s mobile support is still &lt;a href=&quot;https://bevyengine.org/news/bevy-0-3/&quot;&gt;very new&lt;/a&gt;, so the Breakout demo doesn’t work perfectly yet. They’re doing an amazing job nonetheless! We’ve been following their progress, and a lot of contributors worked very hard to make it happen.&lt;/p&gt;

&lt;p&gt;We’d love to see PRs that add template packs for other engines and frameworks, so that cargo-mobile is convenient for anyone and everyone to use. We’d also love to show you a demo using Brainstorm, our own internal mobile-first game engine, but we’re not ready to open source it just yet!&lt;/p&gt;

&lt;p&gt;If you have any questions, issues, or ideas, feel free to &lt;a href=&quot;https://github.com/BrainiumLLC/cargo-mobile/issues&quot;&gt;open an issue&lt;/a&gt;!&lt;/p&gt;</content><author><name>Francesca Lovebloom</name></author><summary type="html">The answer to “how do I use Rust on iOS and Android?”</summary></entry></feed>