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

Add option to build with dynamic libc and c++, but static other dependencies; change static option name #4597

Merged
merged 14 commits into from
Apr 9, 2024

Conversation

vlstill
Copy link
Contributor

@vlstill vlstill commented Apr 4, 2024

Breaking change: CMake option BUILD_STATIC_SANS_GLIBC was renamed to STATIC_BUILD_WITH_DYNAMIC_GLIBC.

The semi-static build that we support now (BUILD_STATIC_SANS_GLIBC) is useful for building binaries that can be redistributed without adding runtime dependencies on dynamic libraries. However, it is only applicable if all the C++-std-library-using dependencies can be linked statically. If a downstream project has some C++ dependencies (that use the standard library) that need to be linked dynamically this leads to inconsistencies in libstd++ initialization which can render the library unusable.

One can of course fall back to fully-dynamic build, but in my opinion it is useful to be able to link dependencies such as Boost, Abseil and Z3 statically even if there are some dependencies that need to be linked dynamically.

This PR introduces a new build option BUILD_STATIC_WITH_DYNAMIC_STDLIB that links all the libraries it can find statically, but the libc and libstdc++ (or other C++ stdlib) are linked dynamically.

@vlstill vlstill added enhancement This topic discusses an improvement to existing compiler code. core Topics concerning the core segments of the compiler (frontend, midend, parser) labels Apr 4, 2024
@vlstill vlstill self-assigned this Apr 4, 2024
@vlstill
Copy link
Contributor Author

vlstill commented Apr 4, 2024

I've also added a CI job for this option. I'm not sure if we want it running all the time, but unless we are quite constrained by the amount of CI runner hours we can use I suggest we keep it.

@fruffy
Copy link
Collaborator

fruffy commented Apr 4, 2024

I've also added a CI job for this option. I'm not sure if we want it running all the time, but unless we are quite constrained by the amount of CI runner hours we can use I suggest we keep it.

I would make it nightly or optional. We are indeed quite constrained on CI hours these days.

@vlstill
Copy link
Contributor Author

vlstill commented Apr 4, 2024

I've also added a CI job for this option. I'm not sure if we want it running all the time, but unless we are quite constrained by the amount of CI runner hours we can use I suggest we keep it.

I would make it nightly or optional. We are indeed quite constrained on CI hours these days.

In that case I suggest making both static variants nightly with option to enable them by a label (probably one label for both), similar to validate or sanitizers. @fruffy If you agree, please disable the "required" on the static-build-test-p4c.

@fruffy
Copy link
Collaborator

fruffy commented Apr 4, 2024

I've also added a CI job for this option. I'm not sure if we want it running all the time, but unless we are quite constrained by the amount of CI runner hours we can use I suggest we keep it.

I would make it nightly or optional. We are indeed quite constrained on CI hours these days.

In that case I suggest making both static variants nightly with option to enable them by a label (probably one label for both), similar to validate or sanitizers. @fruffy If you agree, please disable the "required" on the static-build-test-p4c.

Sounds like a good idea. I think one label is good enough. I will disable the required once this PR is ready to be merged.

@vlstill vlstill added the run-static Use this tag to trigger static build CI run. label Apr 4, 2024
@vlstill vlstill marked this pull request as ready for review April 5, 2024 12:10
@vlstill vlstill requested a review from fruffy April 5, 2024 12:10
CMakeLists.txt Outdated
"Build a (mostly) statically linked release binary. Glibc is linked dynamically." OFF
)
if (BUILD_STATIC_RELEASE_SANS_GLIBC)
OPTION (BUILD_STATIC_RELEASE_SANS_GLIBC "Build a (mostly) statically linked release binary. Glibc \
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might make sense to drop the sans and just use "dynamic". It's a little longer but gets the point across better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what about BUILD_PREFER_STATIC_DYNAMIC_GLIBC/...DYNAMIC_STDLIB? That I think is better aligned with the meaning. "...WITH_DYNAMIC..." would read even better, but the option is quite long already :-/.

Do we want a "deprecated" catch for the old spelling? Or do we expect the downstreams to notice/have tests in place :-). I have no idea who uses this besides the Altera compiler :-D.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah let's just drop it, iirc the Tofino compiler also had its own static build.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we are bikeshedding here but I feel like STATIC_BUILD_PREFER_DYNAMIC_GLIBC is easier to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the thing that is preferred is the static, except for glibc/stdlib. Or we could just drop the PREFER and name this BUILD_STATIC_WITH_DYNAMIC_GLIBC, or even STATIC_BUILD_WITH_DYNAMIC_GLIBC (I feel like the BUILD is a prefix for build options, e.g. also BUILD_LINK_WITH_GOLD etc., but I don't have too strong feelings about this).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Well since I got confused about it it looks like it is a little too ambiguous, STATIC_BUILD_WITH_DYNAMIC_GLIBC is probably the most straightforward?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I've renamed it.

tools/ci-build.sh Outdated Show resolved Hide resolved
tools/ci-check-static.sh Show resolved Hide resolved
@vlstill vlstill force-pushed the sans-stdlib branch 2 times, most recently from 2922ce8 to 097316c Compare April 9, 2024 08:01
@vlstill vlstill requested a review from fruffy April 9, 2024 09:42
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Early approving to unblock things.

@vlstill vlstill changed the title Add option to build with dynamic libc and c++, but static boost and other available dependencies Add option to build with dynamic libc and c++, but static other dependencies; change static option name Apr 9, 2024
@vlstill vlstill requested a review from fruffy April 9, 2024 15:52
@vlstill
Copy link
Contributor Author

vlstill commented Apr 9, 2024

@fruffy, did you already remove the static check from the required once? I'm little surprised I don't see it as missing since it was renamed.

@fruffy
Copy link
Collaborator

fruffy commented Apr 9, 2024

@fruffy, did you already remove the static check from the required once? I'm little surprised I don't see it as missing since it was renamed.

Yes I did

@vlstill vlstill added this pull request to the merge queue Apr 9, 2024
Merged via the queue into p4lang:main with commit ef502dd Apr 9, 2024
18 checks passed
@vlstill vlstill deleted the sans-stdlib branch April 9, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Topics concerning the core segments of the compiler (frontend, midend, parser) enhancement This topic discusses an improvement to existing compiler code. run-static Use this tag to trigger static build CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants