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

Move #includes out of extern "C" blocks #4218

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open

Move #includes out of extern "C" blocks #4218

wants to merge 15 commits into from

Conversation

Victor-C-Zhang
Copy link
Contributor

Do some include shuffling for **.h files within lib, programs, tests, and zlibWrapper. lib/legacy and lib/deprecated are untouched.
#includes within extern "C" blocks in .cpp files are untouched.

todo: shuffling for xxhash.h

I have no way of exhaustively testing this... CI to the rescue?

Do some include shuffling for `**.h` files within lib, programs, tests, and zlibWrapper.
`lib/legacy` and `lib/deprecated` are untouched.
`#include`s within `extern "C"` blocks in .cpp files are untouched.

todo: shuffling for `xxhash.h`
@felixhandte
Copy link
Contributor

You could build the library before and after and see that the symbol list given by nm doesn't change? (I.e., no symbols become mangled.)

@Victor-C-Zhang
Copy link
Contributor Author

@Cyan4973 what should we do about copied deps like fse and xxhash? Does this warrant a PR in their respective repos too?

@Victor-C-Zhang Victor-C-Zhang marked this pull request as ready for review December 20, 2024 01:48
@Cyan4973
Copy link
Contributor

How did you check that this PR fixed #4187 ?

@Victor-C-Zhang
Copy link
Contributor Author

How did you check that this PR fixed #4187 ?

I haven't. I will try to repro #4187 with the limited information provided and do a before-and-after. From reading forum posts of people with similar issues, this may be an issue specific to an old version of apple clang from an old XCode, but I'll need to double-check to make sure...

@Victor-C-Zhang
Copy link
Contributor Author

Update: I was unable to repro the build failure.
Here's what I did:

  1. Generate zstd.c from create_single_file_library.sh
  2. Copy zstd.c and lib/zstd.h, lib/zdict.h, lib/zstd_error.h, lib/module.modulemap to a fresh directory (outside zstd repo) ~/module_test
  3. In the directory ~/module_test use the following main.cpp:
#include "zzz.h"
#include <iostream>
#include <string>

int main() {
  std::cout << "Hello, world!" << std::endl;
  std::string input = "abcdabcdabcdabcdabcdabcdabcdabcd";
  std::string output('\0', input.size() * 100);
  auto res = ZSTD_compress(output.data(), output.size(),
                           input.data(), input.size(), 3);
  std::cout << res << std::endl;

  return 0;
}
  1. For safety, rename the module libzstd -> zzz, and rename zstd.h -> zzz.h, zstd.c -> zzz.c. Also do this in the module.modulemap.
  2. Build with module
clang -shared -o libzzz.dylib zzz.c
clang++ -std=c++20 main.cpp -fmodules -fcxx-modules -L. -lzzz
  1. It runs:
% ./a.out
Hello, world!
18446744073709551546

Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin24.1.0
Thread model: posix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants