You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

5h 36m 40s logged

devlog 3

When I began binding my Go library to Rust today, I had realized something I’ve been doing wrong not just in my Rust bindings but in my C bindings. They both work by calling go build which is fine but not everyone has Go installed on their computer, so it works on mine but not others.

use std::process::Command;

fn main() {
    println!("Hello World!");

    // https://stackoverflow.com/questions/43292357/how-can-one-detect-the-os-type-using-rust
    // https://doc.rust-lang.org/std/process/struct.Command.html
    let _output = if cfg!(target_os = "windows") {
        Command::new("go").args([
            "build",
            "-buildmode=c-shared",
            "-o",
            "mcserverkit.dll",
            "./bindings/c",
        ]);
    } else if cfg!(target_os = "linux") {
        Command::new("go").args([
            "build",
            "-buildmode=c-shared",
            "-o",
            "mcserverkit.so",
            "./bindings/c",
        ]);
    } else if cfg!(target_os = "macos") {
        Command::new("go").args([
            "build",
            "-buildmode=c-shared",
            "-o",
            "mcserverkit.dylib",
            "./bindings/c",
        ]);
    } else {
        println!("Operating system not supported");
        return;
    };
}

the plan

Instead of requiring every person to have Go installed, I created a GitHub action that compiles the library for every platform whenever a new release is published. It generates .dll, .so, .dylib and header files and uploads to release assets.

but it’s only half the process, I still have to rewrite my Rust and C bindings so they download the precompiled assets from the latest GitHub release instead of compiling them locally.

This should actually make the entire logic faster because it won’t need to download the source and run go build every time when it can skip straight to the prebuilt assets, which removes the compiling step entirely!!!

2
28

Comments 0

No comments yet. Be the first!