rust-plus-golang

Rust + Go

Github stars Tracking Chart

Rust + Golang


This repository shows how, by combining
cgo and
Rust's FFI capabilities, we can call
Rust code from Golang.

Run make build and then ./main to see Rust + Golang in action. You
should see Hello John Smith! printed to stdout.

You can do this for your own project

Begin by creating a lib directory, where you will keep your Rust libraries.
Andrew Oppenlander's article on creating a Rust dynamic library is a great introduction.

Then, you need to create a C header file for your library. Just copy the libc
types that you used.

All that is left to do is to add some cgo-specific comments to your Golang
code. These comments tell cgo where to find the library and its headers.

/*
#cgo LDFLAGS: -L./lib -lhello
#include "./lib/hello.h"
*/
import "C"

There should not be a newline between */ and import "C".

A simple make build (use the Makefile in this repository) will
result in a binary that loads your dynamic library.

Main metrics

Overview
Name With Ownermediremi/rust-plus-golang
Primary LanguageMakefile
Program languageMakefile (Language Count: 4)
Platform
License:MIT License
所有者活动
Created At2015-05-09 10:57:59
Pushed At2024-10-24 02:34:31
Last Commit At2024-10-24 11:34:28
Release Count0
用户参与
Stargazers Count779
Watchers Count6
Fork Count62
Commits Count12
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count3
Pull Requests Open Count1
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private