# Is it easy to call Go from Julia? What about Rust? What are the biggest challenges

**URL:** <https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243>\
**Category:** General Usage\
**Created:** [February 14, 2021, 7:13am UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243 "2021-02-14T07:13:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [February 14, 2021, 7:13am UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/1 "2021-02-14T07:13:05Z")

</div>

Is it easy to call Go from Julia? What about Rust? What are the biggest challenges? What about the other direction, i.e. them calling Julia?  
I’m looking for two things. One is that I could do microservices in a modern language that gives me small binaries that execute fast. The other would be to use libraries in one language in the other, so the amount of libraries would be a factor.

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1613286763259100?thread_ts=1613286763.259100&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

**Author:** ![felipenoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felipenoris/32/553_2.png) [@felipenoris](https://discourse.julialang.org/u/felipenoris)\
**Post date:** [February 14, 2021, 12:18pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/2 "2021-02-14T12:18:02Z")

</div>

With Rust, one way to do it is to export Rust functions as C functions with FFI and build a dynamic lib, and then use ccall in the Julia side to call it.  
See [GitHub - felipenoris/JuliaPackageWithRustDep.jl: Example of a Julia Package with Rust dependency.](https://github.com/felipenoris/JuliaPackageWithRustDep.jl)

---

<div class="post-metadata">

**Author:** ![StatisticalMouse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statisticalmouse/32/43370_2.png) [@StatisticalMouse](https://discourse.julialang.org/u/StatisticalMouse)\
**Post date:** [February 14, 2021, 2:29pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/3 "2021-02-14T14:29:09Z")

</div>

There’s also [jlrs - Rust](https://docs.rs/jlrs/0.8.1/jlrs/) that states “The main goal behind jlrs is to provide a simple and safe interface to the Julia C API that lets you **call code written in Julia from Rust and vice versa**.”

And a page in the manual [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/)

---

<div class="post-metadata">

**Author:** ![StatisticalMouse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statisticalmouse/32/43370_2.png) [@StatisticalMouse](https://discourse.julialang.org/u/StatisticalMouse)\
**Post date:** [February 14, 2021, 2:31pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/4 "2021-02-14T14:31:33Z")

</div>

I’d like to know how well this works in practice from someone who used this kind of thing for a real purpose.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [February 14, 2021, 5:30pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/5 "2021-02-14T17:30:51Z")

</div>

I wrapped a function from a Go library recently; Go can generate shared libraries with the c-shared build option, and then you can ccall into them. I think you basically need to write a C-interface on the Go side if it doesn’t have one already. And the c-shared option doesn’t let you pass in and out structs, just basic types. But it seems to work well subject to those limitations.

This is the little C-interface I wrote: [https://github.com/JuliaPackaging/Yggdrasil/blob/6742e470592ab1aaac30a5146916554adcea879d/L/licensecheck/bundled/main.go](https://github.com/JuliaPackaging/Yggdrasil/blob/6742e470592ab1aaac30a5146916554adcea879d/L/licensecheck/bundled/main.go) and [https://github.com/ericphanson/LicenseCheck.jl/blob/d1bc60332cae406cbff86dfeb7023195dcadb2c3/src/LicenseCheck.jl#L33](https://github.com/ericphanson/LicenseCheck.jl/blob/d1bc60332cae406cbff86dfeb7023195dcadb2c3/src/LicenseCheck.jl#L33) is the Julia-side call. I didn’t wrap the whole library, just exposed the functionality I wanted.

(That was my first time writing Go/C code so if anyone sees an error please let me know! The `unsafe` stuff is a little frightening).

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [February 14, 2021, 6:44pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/6 "2021-02-14T18:44:20Z")

</div>

Calling julia from go should be easy enough on the surface with Cgo and the julia c api. Be aware that Cgo is particular about pointers to pointers because they make it hard to manage memory. Memory management between two separate garbage collectors could be challenging if you try to share large data.

---

<div class="post-metadata">

**Author:** ![StatisticalMouse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/statisticalmouse/32/43370_2.png) [@StatisticalMouse](https://discourse.julialang.org/u/StatisticalMouse)\
**Post date:** [February 14, 2021, 7:01pm UTC](https://discourse.julialang.org/t/is-it-easy-to-call-go-from-julia-what-about-rust-what-are-the-biggest-challenges/55243/7 "2021-02-14T19:01:49Z")

</div>

That looks like a perfect example of needing to interface to another language to gain functionality you really don’t want to write yourself! (Also it doesn’t look that easy to write.)
