<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="32674" data-post-id="32674">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="GregFreeman" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  GregFreeman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/cmkarlsson" rel="nofollow">@cmkarlsson</a> and <a class="mention" href="/u/overminddl1" rel="nofollow">@OvermindDL1</a></p>
<p>Are you aware of any open source code that takes care of the Rust compilation and path management for ports?</p>
<p>I’ve been taking a look at <a href="https://github.com/hansihe/rustler/blob/master/rustler_mix/lib/mix/tasks/compile.rustler.ex" rel="noopener nofollow ugc">https://github.com/hansihe/rustler/blob/master/rustler_mix/lib/mix/tasks/compile.rustler.ex</a><br>
and the rest of the Rustler project code and managing ports on a project needs something similar, if I’m not mistaken.</p>
<p>I’ve thought about branching those parts of Rustler needed for ports but I don’t want to repeat it if it’s already been done somewhere else, or if it’s actually not the right thing to do. I’ve also seen the comments here: <a href="https://github.com/hansihe/rustler/issues/78" class="inline-onebox" rel="noopener nofollow ugc">Feature request: support for ports · Issue #78 · rusterlium/rustler · GitHub</a></p>
<p>It doesn’t look that trivial at all to set up a Rust compiler in a mix project, unless I’m missing something.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32674" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-32674" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32674"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="32675" data-post-id="32675">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a href="https://crates.io/crates/eetf" rel="noopener nofollow ugc">eetf</a> is all you need to do rust Ports.  A port is just an external running application communication with the EVM via stdin/stdout, that is all, and if you want to use erlang’s external term format for speed then eetf handles that, or you can marshall information however you want otherwise.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32675" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-32675" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32675"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="32864" data-post-id="32864">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="GregFreeman" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  GregFreeman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Ok it looks like I’ll still need to figure out something to manage automatic compilation with Mix. EETF is purely Rust code.</p>
<p>I could take the existing Rustler Mix code, as linked above, and re-purpose it to manage the Rust files.</p>
<p>I think that’s what I’m really asking. Rustler is really nice in that it can identify if compilation is needed and sets up taking care of the paths and binaries.</p>
<p>EETF by itself is not enough to make a project tying both Elixir and Rustl together very automatic. This is probably why Rustler is so much more popular.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="32864" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-32864" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="32864"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #23"></div>
  </section>
</div>
    <div class="postbit" id="33157" data-post-id="33157">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="GregFreeman" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  GregFreeman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Here’s the state of my journey with ports with Rust and Elixir:</p>
<p>I can get Nifs to work fairly well, however I understand the disadvantages.</p>
<p>However, getting ports to work has been a bit of a nightmare because help is sparse.</p>
<p>I finally got to the point where I think I’m close, but not there yet.</p>
<p>Using Rustler, I can get the linking to work and point to the .so (driver) compiled file.</p>
<p>I can then attempt to load the driver using :erl_ddll.load(“path/to/so”, :soname). But, I get the error from erlang that “No driver init in dynamic library.”</p>
<p>Is there anyone out there that can help me out with fixing that?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33157" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-33157" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33157"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #24"></div>
  </section>
</div>
    <div class="postbit" id="33158" data-post-id="33158">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cmkarlsson" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cmkarlsson/120/23000_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cmkarlsson
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi Greg,</p>
<p>Sorry if this is a bit of a non-answer to the actual question.</p>
<p>You can use linked in drivers but I think you want a plain port. <strong>Port Drivers</strong> existed before NIFs and also has the drawback of crashing the entire VM if something goes wrong. I think most people use NIFs instead of Port Drivers today but I may be wrong. For example I know the crypto library in erlang used to be a port driver but is now implemented as a NIF.</p>
<p>A plain port is just a standalone application which communicate with erlang using file descriptors (they recommend 3 and 4 but stdin/stdout can be used to)</p>
<p>All the integration options are found here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://www.erlang.org/doc/system/tutorial.html">
  <header class="source">

      <a href="https://www.erlang.org/doc/system/tutorial.html" target="_blank" rel="noopener nofollow">erlang.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://www.erlang.org/doc/system/tutorial.html" target="_blank" rel="noopener nofollow">Introduction — Erlang System Documentation v29.0.2</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>And the normal port integration here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://www.erlang.org/doc/system/c_port.html">
  <header class="source">

      <a href="https://www.erlang.org/doc/system/c_port.html" target="_blank" rel="noopener nofollow">erlang.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://www.erlang.org/doc/system/c_port.html" target="_blank" rel="noopener nofollow">Ports — Erlang System Documentation v29.0.2</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>The port example uses C but any language can be used. There are no dependencies on erlang at all. The only thing is that you have to implement your custom protocol to talk to the port.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33158" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-33158" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33158"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #25"></div>
  </section>
</div>
    <div class="postbit" id="33175" data-post-id="33175">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="GregFreeman" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  GregFreeman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks,</p>
<p>That actually told me quite a bit. In trying to figure out Ports, I got bare ports to work with binary files. However, the trouble came up when trying to get the standard compilation to dylibs by Rustler. I could only get port drivers to work in that case.</p>
<p>However, by playing around with the cargo.toml for the port code, I was able to get the binary to work. It’s automatically recompiled with rustler, but the binary file doesn’t get placed in the proper native folder. So, it’s a partial solution.</p>
<p>I couldn’t figure out the rustler mix task that may allow for binary compilation…maybe the owner will be nice and either tell me how I should do it or someone else knows.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33175" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/27">Post #26</a>
	                </div>
	            </div>
              <div id="likers-container-33175" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33175"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #26"></div>
  </section>
</div>
    <div class="postbit" id="33388" data-post-id="33388">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="GregFreeman" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  GregFreeman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>After a lot of struggle and seemingly trying everything possible to get ports working, including trying the difficult port drivers and digging into erlang calls themselves, I got a rust/elixir port working!</p>
<p>The embarrassing part was I didn’t realize that a newline character was needed for the rust read_line function to return.</p>
<p>However, this is exactly what I’ve been after! A great language for a distributed webserver and a great language for nitty gritty numerical work that isn’t as unsafe as C or as archaic as Fortran. Then, add Phoenix, throw in some JS/HTML/CSS/SQL for good measure, and you have everything you could possibly want.</p>
<p>Example posted here, with the Nif example: <a href="https://github.com/cgregfreeman/phoenix_rust_ports_and_nifs" class="inline-onebox" rel="noopener nofollow ugc">GitHub - cgregfreeman/phoenix_rust_ports_and_nifs: Examples of Phoenix with Rust interfaces via both ports and nifs · GitHub</a></p>
<p>Now I can get on with what I originally set out to do.</p>
<p>Thank you everyone here. I hope my examples are useful to you.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33388" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/what-do-you-think-about-integrating-rust-and-elixir/4939/28">Post #27</a>
	                </div>
	            </div>
              <div id="likers-container-33388" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33388"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>