build, refactor: Rely on AC_DEFINE macro #24774

pull hebasto wants to merge 4 commits into bitcoin:master from hebasto:220405-config changing 6 files +20 −4
  1. hebasto commented at 4:12 pm on April 5, 2022: member

    On master (9ce1c506a3a5d20b1bf254235bfae48af592d86c) the ENABLE_ARM_SHANI, ENABLE_AVX2, ENABLE_SSE41, and ENABLE_X86_SHANI macros are defined twice in the build system. First time, using the AC_DEFINE macro in the configure script. And second time, in Makefile as a part of CPPFLAGS.

    This PR removes such duplication.

    This change is required for bitcoin/bitcoin#24773.

  2. DrahtBot added the label Build system on Apr 5, 2022
  3. DrahtBot added the label Utils/log/libs on Apr 5, 2022
  4. in src/Makefile.am:502 in 047e7bd7d5 outdated
    498@@ -499,27 +499,19 @@ crypto_libbitcoin_crypto_base_a_SOURCES += crypto/sha256_sse4.cpp
    499 endif
    500 
    501 crypto_libbitcoin_crypto_sse41_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
    502-crypto_libbitcoin_crypto_sse41_a_CPPFLAGS = $(AM_CPPFLAGS)
    


    laanwj commented at 12:24 pm on April 6, 2022:
    Are you sure that setting CPPFLAGS is not needed anymore?

    hebasto commented at 12:44 pm on April 6, 2022:
    Thanks! Fixed.
  5. hebasto force-pushed on Apr 6, 2022
  6. Empact commented at 3:20 pm on April 6, 2022: member

    Just to be clear on my understanding: this removes the definitions in these files in the case where they do not pass the test in configure.ac. The reason the current behavior is not broken where these functions are defined despite missing required behavior, is that while these functions are always included, their callers also check for the definitions, and that prevents their being called in those cases. Is that right?

    If so, would it be worthwhile and feasible to remove these archives entirely, in the cases where the functionality is not present? E.g. crypto_libbitcoin_crypto_sse41_a includes only crypto/sha256_sse41.cpp. which only defines functionality if ENABLE_SSE41 is defined.

  7. hebasto commented at 3:55 pm on April 6, 2022: member

    Just to be clear on my understanding: this removes the definitions in these files in the case where they do not pass the test in configure.ac.

    The build system includes the crypto parts only when the related checks passed https://github.com/bitcoin/bitcoin/blob/41720a1f540ef3c16a283a6cce6f0a63552a4937/src/Makefile.am#L40-L56

  8. laanwj commented at 12:15 pm on April 7, 2022: member

    Build system review and concept ACK 825143174e7a91bf644b980b4e133ace13e898fe

    Including the config header instead of relying on definitions on the command line is a no-brainer.

    I would guess this doesn’t need parallel changes to the MSVC build system because it doesn’t support special instruction sets yet.

  9. laanwj commented at 12:16 pm on April 7, 2022: member
    Thinking of it, why do we compile these files at all when the respective option is disabled? #ifdefing out the entire source file is a bit curious (but maybe I’m missing something).
  10. fanquake commented at 12:44 pm on April 7, 2022: member
    Some of this might have been done (at some point) to support weird / nonstandard / non-autoconf builds in some way, i.e similar to https://github.com/bitcoin/bitcoin/blob/323d4c09c090a0c74b2fbedfb2cd575f1dd839f3/src/compat/endian.h#L23-L25
  11. laanwj commented at 1:39 pm on April 7, 2022: member
    I can see a slight point for a library like libbitcoin_consensus; e.g. if you want to build it as part of a.rust binding, you don’t particularly want to call into automake/autoconf. Still. I’m not sure having files compiled only when e.g. ENABLE_AVX2 is set, then having the whole file guarded with #ifdef ENABLE_AVX2…#endif helps there.
  12. hebasto commented at 4:46 pm on April 7, 2022: member

    @laanwj

    Thinking of it, why do we compile these files at all when the respective option is disabled?

    What does make you think so?

    For example, when the configure script fails to check AC_MSG_CHECKING([for x86 SHA-NI intrinsics]) ..., the sha256_x86_shani.cpp source file is not compiled. Also #24774 (comment).

  13. hebasto commented at 4:49 pm on April 7, 2022: member

    e.g. if you want to build it as part of a.rust binding, you don’t particularly want to call into automake/autoconf.

    Also we do not use automake/autoconf when building with MSVC.

  14. DrahtBot commented at 11:46 am on April 15, 2022: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #25302 (build: Check usages of #if defined(…) by brokenprogrammer)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  15. fanquake commented at 10:39 am on April 17, 2022: member

    This PR removes such duplication.

    I bought this up very briefly with Cory, and he said that this was done on purpose. So this change shouldn’t be made under the guise of “duplication”, and/or move ahead until he weighs in here. If this code does have other use cases then we need to evaluate whether removing it just to support things in the MSVC build is actually more worthwhile.

  16. hebasto commented at 3:09 pm on April 17, 2022: member

    I bought this up very briefly with Cory, and he said that this was done on purpose.

    What is the purpose?

  17. theuni commented at 8:11 pm on April 21, 2022: member

    @hebasto whoops, sorry for the delayed response.

    It’s rather convenient imo to have the crypto folder work outside of Core. I use it often as a quick way to add a known/trustworthy sha2 impl to another project, like here: https://github.com/theuni/libutreexo

    I believe @TheBlueMatt has done/does something similar for some of his projects.

    So for what’s in crypto/ at least, unless it’s somehow problematic, I’d much prefer to keep the need for bitcoin-config.h to a minimum.

  18. DrahtBot added the label Needs rebase on Apr 28, 2022
  19. build, refactor: Rely on `AC_DEFINE([ENABLE_ARM_SHANI])`
    This change deduplicates the `ENABLE_ARM_SHANI` macro in the build
    system.
    a70b4db864
  20. build, refactor: Rely on `AC_DEFINE([ENABLE_AVX2])`
    This change deduplicates the `ENABLE_AVX2` macro in the build system.
    144dc2ff44
  21. build, refactor: Rely on `AC_DEFINE([ENABLE_SSE41])`
    This change deduplicates the `ENABLE_SSE41` macro in the build system.
    0b5ec3af92
  22. build, refactor: Rely on `AC_DEFINE([ENABLE_X86_SHANI])`
    This change deduplicates the `ENABLE_X86_SHANI` macro in the build
    system.
    6241d16795
  23. hebasto force-pushed on May 28, 2022
  24. hebasto commented at 12:58 pm on May 28, 2022: member
    Rebased 825143174e7a91bf644b980b4e133ace13e898fe -> 6241d16795e181f1d8ae11493f6e7034bdec9ea9 (pr24774.02 -> pr24774.03) due to conflict with #24322.
  25. hebasto commented at 1:12 pm on May 28, 2022: member

    @theuni

    I’d much prefer to keep the need for bitcoin-config.h to a minimum.

    This change does not make the bitcoin-config.h required. It remains optional, i.e., only when the HAVE_CONFIG_H is defined.

    It’s rather convenient imo to have the crypto folder work outside of Core. I use it often as a quick way to add a known/trustworthy sha2 impl to another project, like here: https://github.com/theuni/libutreexo

    I believe @TheBlueMatt has done/does something similar for some of his projects.

    I believe all of the cases mentioned above are still working with this PR without any adjustments.

    In other words, this PR makes crypto recognize bitcoin-config.h as an additional build option. All other build options, which do not use bitcoin-config.h, are not affected.

  26. DrahtBot removed the label Needs rebase on May 28, 2022
  27. achow101 commented at 7:09 pm on October 12, 2022: member
    Are you still working on this?
  28. hebasto closed this on Oct 12, 2022

  29. bitcoin locked this on Oct 12, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 13:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me