Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Experiments with bazel build system #24

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

pawelchcki
Copy link
Contributor

@pawelchcki pawelchcki commented Feb 18, 2022

Why try Bazel ?

libddprof build system is already a bit complex- having 4 (cargo, custom dockerfiles with build dependencies, bash, and CI) components necessary to produce the final artifacts. With more supported configurations added it might get even more complex, in order to support all edge cases

Bazel has the potential to simplify some of that, as it can handle most of build dependencies, and has unparalleled control over the shape of the final artifact.

  • can be really good at caching (building the library in seconds), including not running tests which haven't been affected by the change
  • can still coexist with platform native tools like Cargo (e.g. through cargo raze, we can update rust dependencies in Cargo.tomls)

This PR is only an experiment (for now :) ) to see what (if anything) could actually be gained from using it to produce the final artifacts.

Smaller binaries ?

Posting this PR a bit earlier than planned. Actually I was just experimenting with Bazel without expecting to post a PR at all....
But I discovered it can compile the shared library and static library, at significantly smaller binary sizes than cargo!
Though it's possible something is missing from cargo config, or that the binaries are invalid, although that is not very likely.

-Currently the size for release version (bazel build) for the .so file is 6MB and 20MB for .a vs 18MB and 100 MB for cargo.-
Update: it turned out that bazel build didn't generate the debuginfo from the binaries by default. With debuginfo the sizes are almost identical (+30kB on bazel side)

Usage:

# install bazelisk (bazel version wrapper) -if its not already installed
bazel build //... # grab a coffe on the first build 😬 
bazel build //ddprof-ffi --config=release # to get the shared library that is 6 MB
bazel test //... 

Still TODO:

  • get rid of the boilerplate generated by cargo raze from the repository (possible to generate it manually before each build, or via repository rule)
  • include cbindgen generation
  • reimplement package_ffi.sh through bazel
  • add Ruby tests to Bazel so that bazel test //ruby/... works too (nice to have)
  • configure toolchain for alpine (to use alpine provided rust)
  • Finish CI setup (current setup only uses github actions - https://github.com/pawelchcki/libddprof/runs/5232784917)

@pawelchcki
Copy link
Contributor Author

pawelchcki commented Feb 18, 2022

Heads up - I've run into an issue on my osx laptop (due to recently updated xcode)
bazelbuild/bazel#14395

Works fine in OSX Ci and on lInux. so YMMV

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant