Skip to content
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

PROD-3069: Cross-compile self contained binaries #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jossemargt-cto-ai
Copy link
Contributor

@jossemargt-cto-ai jossemargt-cto-ai commented Sep 11, 2023

Why

Although we managed to generate binaries for multiple architectures on #6, we still had plenty opportunities of improvement like:

  • Cross platform compilation without chipset emulation
    • Reduce CI time (byproduct of chipset emulation)
  • Generating self contained binaries, so they can run regardless the existing glibc version (or absence of it).
    • AKA run on Alpine or distroless environments

What

By switching from OpenSSL into rustls from one of the dependencies, we were able to move from glibc into musl. By using the latter C standard library the rust compiler is able to build self contained binaries.

Extra

The real changes are on the Cargo.toml and the .github/workflows/wc_buid_binaries.yml files, the rest is code grooming.

By the way, with taking the chipset emulation out of the picture we reduced the cross-build time from ~30 minute to ~7 minutes 🎉🎉🎉

@jossemargt-cto-ai jossemargt-cto-ai self-assigned this Sep 11, 2023
@jossemargt-cto-ai jossemargt-cto-ai force-pushed the feature/xcompile-self-contained-binaries branch 4 times, most recently from 7854d2d to d2a7e44 Compare September 14, 2023 19:13
@jossemargt-cto-ai jossemargt-cto-ai marked this pull request as ready for review September 14, 2023 19:27
@jossemargt-cto-ai jossemargt-cto-ai changed the title Cross-compile self contained binaries PROD-3069: Cross-compile self contained binaries Sep 14, 2023
Up to this iteration we used to link our binaries to the GNU C library
(AKA glibc), which works fine for most of GNU distributions. However,
it is well known that managing said system dependency comes at a great
maitenance cost, so it would be best to ship self-contained binaries by
migrating into the musl C library.

Turns out, the only dependency that tied us to glibc was OpenSSL which
is no longer required for our HTTP client. So by changing some cargo
configurations we were able to do the switch we were aiming for.

This change came with the additional benefit of enabling cross
compiliation without relying on chip emulation, which is way faster! To
the point of reducing the CI time and billing by at least 5x.

Signed-off-by: Jonnatan Jossemar Cordero <jossemar.cordero@cto.ai>
@jossemargt-cto-ai jossemargt-cto-ai force-pushed the feature/xcompile-self-contained-binaries branch 2 times, most recently from 6625939 to 5948918 Compare September 15, 2023 23:01
Copy link

@nitishkumar71 nitishkumar71 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

.github/workflows/wc_buid_binaries.yml Outdated Show resolved Hide resolved
@jossemargt-cto-ai jossemargt-cto-ai force-pushed the feature/xcompile-self-contained-binaries branch 2 times, most recently from 24cd9f6 to 7934e79 Compare September 18, 2023 21:14
Since cross compiling requires a couple of extra setup, we decided to
move the build logic into a reusable workflow so there's only one way of
doing things regarding CI.

Signed-off-by: Jonnatan Jossemar Cordero <jossemar.cordero@cto.ai>
Signed-off-by: Jonnatan Jossemar Cordero <jossemar.cordero@cto.ai>
@jossemargt-cto-ai jossemargt-cto-ai force-pushed the feature/xcompile-self-contained-binaries branch from 7934e79 to a54fb86 Compare September 18, 2023 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants