Skip to content

disable CGO on every OS except macOS #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2022
Merged

disable CGO on every OS except macOS #1751

merged 1 commit into from
Jun 13, 2022

Conversation

umbynos
Copy link
Contributor

@umbynos umbynos commented Jun 8, 2022

Please check if the PR fulfills these requirements

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • What kind of change does this PR introduce?

enhancement

  • What is the current behavior?

The Arduino CLI is built with CGO_ENABLED=1:

Cgo enables the creation of Go packages that call C code

This does not allow the cli to be a fully static binary. We have to use CGO because of go.bug.st/serial.v1/enumerator used by go.bug.st/serial:

This library tries to avoid the use of the "C" package (and consequently the need of cgo) to simplify cross compiling. Unfortunately the USB enumeration package for darwin (MacOSX) requires cgo to access the IOKit framework. This means that if you need USB enumeration on darwin you're forced to use cgo.

  • What is the new behavior?

CGO is disabled on every OS except macOS. This gives some advantages (for example on Linux amd64):
new

$ file arduino-cli 
arduino-cli: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
$ ldd arduino-cli 
        not a dynamic executable
$ ls -l arduino-cli
-rwxr-xr-x 1 root root 27278394 giu  8 11:51 arduino-cli*

old

$ file arduino-cli 
arduino-cli: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, not stripped
$ ldd arduino-cli 
        linux-vdso.so.1 (0x00007fffbdd7e000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007faf86ede000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007faf86aed000)
        /lib64/ld-linux-x86-64.so.2 (0x00007faf870fd000)
$ ls -l arduino-cli
-rwxr-xr-x 1 root root 27355615 giu  8 12:22 arduino-cli*

nop

  • Other information:

See how to contribute

@umbynos umbynos added type: enhancement Proposed improvement os: windows Specific to Windows operating system os: linux Specific to Linux operating system topic: packaging Related to the release distribution package labels Jun 8, 2022
@umbynos umbynos requested a review from a team June 8, 2022 10:25
@umbynos umbynos self-assigned this Jun 8, 2022
@umbynos umbynos linked an issue Jun 8, 2022 that may be closed by this pull request
@umbynos umbynos merged commit 76fab32 into master Jun 13, 2022
@umbynos umbynos deleted the umbynos/cgo branch June 13, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os: linux Specific to Linux operating system os: windows Specific to Windows operating system topic: packaging Related to the release distribution package type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arduino-cli: not found. Sopine A64 on OpenWrt OS
2 participants