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

Learn from MiniPortile2's mkmf_config to simplify building vendored dependencies #138

Merged
merged 2 commits into from
Apr 1, 2024

Commits on Apr 1, 2024

  1. Refactor extconf, inspired by MiniPortile2

    GitHub: #109
    
    MiniPortile2 2.8.5 ships with a `mkmf_config` feature that can handle
    statically linking libraries for us, however it doesn't currently work
    with our use case due to Abseil shipping with over 180 separate `.pc`
    files. That said, we can still update how we statically link RE2 into
    the gem based on MiniPortile2's strategy and how Ruby's own
    MakeMakefile's `pkg_config` works.
    
    The key is that we now rely on the output of the following `pkg-config`
    commands to populate `$LIBPATH`, `$libs`, `$LDFLAGS`, `$INCFLAGS`,
    `$CFLAGS` and `$CXXFLAGS` respectively:
    
    * `pkg-config --libs-only-L --static`
    * `pkg-config --libs-only-l --static`
    * `pkg-config --libs-only-other --static`
    * `pkg-config --cflags-only-I --static`
    * `pkg-config --cflags-only-other --static`
    
    We transform any libraries into static ones by replacing them with their
    absolute path wherever possible.
    
    Note we _must not_ use MakeMakefile's `dir_config` to avoid accidentally
    adding a non-absolute (and therefore dynamic) reference to RE2 which
    risks accidentally linking against the wrong version of the library,
    especially if it is found in Ruby's default `exec_prefix` (e.g.
    `/usr/local`).
    
    We also take a leaf from the Ruby SQLite3 gem's extconf
    (https://github.com/sparklemotion/sqlite3-ruby/blob/ae5c13996f936fce07e8a5e9fb6aaf2ede5d82b7/ext/sqlite3/extconf.rb#L113)
    and re-organise the configuration logic in our extconf.rb into a class
    rather than a series of global functions.
    
    Thanks to @flavorjones for his work on MiniPortile2 and @stanhu for
    reviewing a draft of this change.
    mudge committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    60ca676 View commit details
    Browse the repository at this point in the history
  2. Run all tests with frozen string literals enabled

    To catch any accidental errors mutating frozen strings, enable them by
    default in CI.
    
    See https://ruby.social/@byroot/112177840865649404
    mudge committed Apr 1, 2024
    Configuration menu
    Copy the full SHA
    792c992 View commit details
    Browse the repository at this point in the history