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

refactor: clean up CMakelists.txt #4779

Merged
merged 7 commits into from
Sep 26, 2024
Merged

refactor: clean up CMakelists.txt #4779

merged 7 commits into from
Sep 26, 2024

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Sep 18, 2024

Description of changes:

I was reading through out CMakeLists.txt and noticed a number of odd/unused configurations. This PR removes them.

  • Wno-missing-braces is not needed for libs2n jk, GCC 4 strikes again
  • replace a regex with the simpler get_filename_component
  • remove unnecessary headers from testlib definition
  • remove the -fPIC compile option on tests, since it is already specified as a public option on libs2n
  • specify the compile definition _POSIX_C_SOURCE=200809L using the dedicated target_compile_definition syntax
  • specify linker options -fsanitize=fuzzer -lstdc++ using the dedicated target_link_options syntax
  • remove unnecessary target_include_directories(${TEST_NAME} PRIVATE ./)
  • remove unused LD_PRELOAD allocator_overrides

Call-outs:

Allocator Overrides

allocator_overrides is never used when tests are run through CMake. Original motivation for the test can be found in these PRs

From the above PRs, the goal with the allocator overrides was the help catch places that we were using uninitialized variables. My current take is the -Wuninitialized (which we currently use) and clang-static-analyze (which we don't) are more robust ways of catching these errors. As such, I would vote for fully removing the allocator overrides ones we have deprecated the make builds.

Section Headers

I know that my big section header comments might be polarizing, but the motivation was as follows

  • the BUILD_TESTING section is getting extremely long
  • there is no syntax highlighting, so it's just a wall of difficult to read text.

That's why I think the very hefty section headers are justified. A single comment is just going to get lost in the wash of monocolored text.

Compile Options: Individual Lines

The compile options were getting very difficult to read. Additionally, having them on a single line makes the git blame much more useful.

Testing:

All CI should pass

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added the s2n-core team label Sep 18, 2024
I actually can't replace the other shared lib with the one used for unit
tests, because the fuzz tests need to be dynamically linked because they
rely on LD_PRELOAD to clobber certain symbols.
no-missing-braces is required for GCC 4 support
@jmayclin jmayclin marked this pull request as ready for review September 19, 2024 23:17
Copy link
Contributor

@jouho jouho left a comment

Choose a reason for hiding this comment

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

Not disagreeing with the section header, but you can get syntax highlighting on CMake file if you get extension on VS Code which made my life x10 easier.

Thank you for cleaning this up!

Copy link
Contributor

@lrstewart lrstewart left a comment

Choose a reason for hiding this comment

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

Love the cleanup!

My suggestion for a PR like this would be to comment on your own PR in-line with explanations of the various changes, rather than summarizing in the description. I've found that helps when the reasoning behind line changes aren't clear, but a persistent code comment wouldn't make sense (particularly for deletes).

CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
add_custom_command(
TARGET testss2n POST_BUILD
COMMAND
objcopy --redefine-syms libcrypto.symbols lib/libtestss2n.a
)
endif()

#run unit tests
file (GLOB TEST_LD_PRELOAD "tests/LD_PRELOAD/*.c")
Copy link
Contributor Author

@jmayclin jmayclin Sep 20, 2024

Choose a reason for hiding this comment

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

Removing this because it is unused. I searched the entire codebase (not just CMakeLists.txt) and found that this library is only used when unit tests are run through make. See the PR overview for my thoughts on why we should totally delete this library.


add_library(testss2n STATIC ${TESTLIB_HEADERS} ${TESTLIB_SRC} ${EXAMPLES_SRC})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Headers shouldn't be included as part of the add_library directive. Generally the add_library directive is just used for things that generate object files. Header should then be added through target_include_directories, but that is already configured to add the tests/ path.

CMakeLists.txt Show resolved Hide resolved
@jmayclin jmayclin enabled auto-merge (squash) September 24, 2024 01:04
@jmayclin jmayclin merged commit cf91291 into aws:main Sep 26, 2024
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants