Skip to content

build: add check for static builds #1846

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
Aug 7, 2025

Conversation

fabbione
Copy link
Contributor

@fabbione fabbione commented Aug 5, 2025

tests/init needs glibc-static (or equivalent) available to run the test suite.

update configure.ac to check for libtool ability to link statically

update Makefile.am to build tests only if static linking is available

update rpm/crun.spec to BuildRequires glibc-static

update tests/*/Dockerfile to include glibc-static

Copy link

sourcery-ai bot commented Aug 5, 2025

Reviewer's Guide

Ensures reliable static builds by importing an Autoconf macro to test linker flags, adding a configure-time check for '-static-libgcc -static', and updating the test suite makefile to use the corrected static flags.

Class diagram for new macro and build configuration

classDiagram
    class configure_ac {
        +AX_CHECK_LINK_FLAG
        +Check for '-static-libgcc -static'
    }
    class ax_check_link_flag_m4 {
        +AX_CHECK_LINK_FLAG(FLAG, ACTION-SUCCESS, ACTION-FAILURE, EXTRA-FLAGS, INPUT)
    }
    class Makefile_am {
        +tests_init_LDFLAGS = -static-libgcc -static
    }
    configure_ac --> ax_check_link_flag_m4 : uses macro
    Makefile_am --> configure_ac : uses flags set by
Loading

Flow diagram for static build flag verification in configure.ac

flowchart TD
    Start([Start configure]) --> CheckFlags{Check '-static-libgcc -static' linker flags}
    CheckFlags -- Success --> Proceed[Continue configuration]
    CheckFlags -- Failure --> Error[Show error: 'Unable to create static linked binaries. make sure glibc-static or equivalent are installed']
Loading

File-Level Changes

Change Details Files
Introduce macro for checking linker flags
  • Add AX_CHECK_LINK_FLAG definition from the Autoconf Archive
m4/ax_check_link_flag.m4
Add static link-flag validation in configure.ac
  • Invoke AX_CHECK_LINK_FLAG for '-static-libgcc -static'
  • Emit an error if static linking support is missing
configure.ac
Update test suite to use consistent static flags
  • Replace '-all-static' with '-static' in tests_init_LDFLAGS
Makefile.am

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fabbione - I've reviewed your changes - here's some feedback:

  • The m4 macro file is a direct copy from the autoconf-archive; consider pulling in the archive via a submodule or other mechanism to simplify maintenance and upstream updates.
  • If you have any C++ dependencies, you may also need to check for and pass -static-libstdc++ alongside -static-libgcc to ensure full static linking of C++ symbols.
  • The AX_CHECK_LINK_FLAG macro ends with a call to AX_CHECK_LINK_FLAGS instead of AX_CHECK_LINK_FLAG—please correct the macro name for consistency and to prevent any lookup issues.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The m4 macro file is a direct copy from the autoconf-archive; consider pulling in the archive via a submodule or other mechanism to simplify maintenance and upstream updates.
- If you have any C++ dependencies, you may also need to check for and pass -static-libstdc++ alongside -static-libgcc to ensure full static linking of C++ symbols.
- The AX_CHECK_LINK_FLAG macro ends with a call to AX_CHECK_LINK_FLAGS instead of AX_CHECK_LINK_FLAG—please correct the macro name for consistency and to prevent any lookup issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@fabbione fabbione force-pushed the fix-glibc-static-detection branch 2 times, most recently from 8e902bb to 60da7db Compare August 5, 2025 09:16
@giuseppe
Copy link
Member

giuseppe commented Aug 5, 2025

a few more tests to fix

@fabbione fabbione force-pushed the fix-glibc-static-detection branch 2 times, most recently from e7a9aa0 to da6a3e1 Compare August 6, 2025 09:15
tests/init needs glibc-static (or equivalent) available to run
the test suite.

update configure.ac to check for libtool ability to link statically

update Makefile.am to build tests only if static linking is available

update rpm/crun.spec to BuildRequires glibc-static

update tests/*/Dockerfile to include glibc-static

Signed-off-by: Fabio M. Di Nitto <[email protected]>
@fabbione fabbione force-pushed the fix-glibc-static-detection branch from da6a3e1 to eb9912e Compare August 6, 2025 09:16
Comment on lines +170 to +172
if BUILD_TESTS
UNIT_TESTS = tests/tests_libcrun_utils tests/tests_libcrun_ring_buffer tests/tests_libcrun_errors tests/tests_libcrun_intelrdt
endif
Copy link
Member

Choose a reason for hiding this comment

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

does it affect make dist and what files are included in the tarball if we build without glibc-static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn´t affect make dist (tested on fedora42). autotools is smart enough to comment out only the build section for the tools and keep the _SOURCE bits for *_DIST sections.

Just one example:

$ grep tests_libcrun_utils Makefile
am__tests_tests_libcrun_utils_SOURCES_DIST =  \
        tests/tests_libcrun_utils.c

and just to be 100% safe. Done 2 make dist, one with glib-static and one without:

crun-without/tests$ ls -1 | wc -l
34

crun-with/tests$ ls -1 | wc -l
34

fabbione@mazikeen:~/work/containers$ diff -Naurd crun-without/ crun-with
fabbione@mazikeen:~/work/containers$

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit ca8e5c7 into containers:main Aug 7, 2025
43 checks passed
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