Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Go without CGo: Alternative Methods and New A...

Go without CGo: Alternative Methods and New Approaches

Avatar for Murat Mirgün ERCAN

Murat Mirgün ERCAN

September 26, 2026

More Decks by Murat Mirgün ERCAN

Other Decks in Technology

Transcript

  1. Topics 1 About Me 2 Introduction 3 The Price of

    Convenience 4 Performance and Reliability
  2. Who Am I ? Software Engineer at @ OSS Maintainer

    @ Formerly: @Permify, @Getir, @VirtualMetric
  3. Introduction cgo is a powerful tool that enables Go programs

    to interact with C code. Using cgo comes with trade-offs that can impact your project's development, performance, and deployment. It's crucial to carefully consider the implications of using cgo before incorporating it into your Go project.
  4. Slower builds:cgo requires additional steps for compiling and linking C

    code, significantly increasing build times. Complex Builds:cgo introduces dependencies on external tools and makefiles, complicating the build process. Cross-platform builds become more challenging, requiring additional configuration and managing multiple toolchains and build environments can be cumbersome and time-consuming.
  5. CGo: When do you REALLY need it? Undeniable Necessity:cgo is

    a valuable tool for interfacing with low-level system APIs, hardware drivers, and legacy C code. In these cases, cgo may be the only viable option to achieve the desired functionality.
  6. Key Questions for Decision Is cross-platform compilation a critical requirement

    for your project? Will performance be a major factor in your application? How complex is your build and deployment process? Are your developers familiar with working with cgo and Go? Do you have the resources and expertise to manage the complexities of cgo?
  7. Cross Compile Go with Zig Cross compiling with Go is

    usually straighforward: set GOOS and GOARCH environement variables and then go build. Unfortunately for projects that uses CGO dependencies things can be harder. Depending on the target architecture it requires to install a C compiler like gcc, clang or x86_64-w64-mingw64-gcc and configure additional environment variables like CC along with the CGO_ENABLED=1 one.
  8. References: CGO Golang Docs CGo is not Go Fyne Project

    Compile With Zig Go Cli CGo Commands Zig Makes Go Cross Compilation Just Work