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

Makefile: Compile zlib .c files with DMD via importC #8865

Merged
merged 2 commits into from
Dec 31, 2023

Conversation

kinke
Copy link
Contributor

@kinke kinke commented Dec 18, 2023

According to earlier CI results, this works - except for a problem on Win64 only:

phobos64.lib(gzwrite.obj) : error LNK2019: unresolved external symbol __va_start referenced in function gzprintf

So looks like this __va_start could be a candidate for inclusion in druntime's __builtins.di (which already defines a __builtin_va_start alias).

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @kinke! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#8865"

This fixes an undefined `__va_start` symbol for the zlib parts,
a problem on Win64 only so far.

The Microsoft headers use something like this (`vadefs.h`) for
x86_64:

```
void __cdecl __va_start(va_list* , ...);
```

The signature of their intrinsic isn't compatible with druntime's
`va_start` (which takes the first param as `out` ref, not as
explicit pointer), so I sadly don't see a way to handle this in
druntime's `__builtins.di` (or `importc.h`).
@kinke
Copy link
Contributor Author

kinke commented Dec 19, 2023

Argh, the Microsoft headers use something like this (vadefs.h) for x86_64:

void __cdecl __va_start(va_list* , ...);
#define __crt_va_start_a(ap, x) ((void)(__va_start(&ap, x)))

The signature of their intrinsic isn't compatible with druntime's va_start (which takes the first param as out ref, not as explicit pointer), so I sadly don't see a way to handle this in druntime's __builtins.di (or importc.h).

I've worked around it for now, via #if __IMPORTC__ special case in the zlib source. :/

@dkorpel
Copy link
Contributor

dkorpel commented Dec 30, 2023

Is this ready to go?

@kinke kinke marked this pull request as ready for review December 31, 2023 11:56
@kinke
Copy link
Contributor Author

kinke commented Dec 31, 2023

The zlib hack obviously isn't ideal, but probably better than keeping on using the C compiler.

@dkorpel dkorpel merged commit 893fb2c into dlang:master Dec 31, 2023
14 checks passed
@dkorpel
Copy link
Contributor

dkorpel commented Dec 31, 2023

I opened an issue for it: https://issues.dlang.org/show_bug.cgi?id=24310

@kinke kinke deleted the zlib_importc branch December 31, 2023 14:16
@ibuclaw
Copy link
Member

ibuclaw commented Jan 1, 2024

Looks like this broke Windows builds on DMD.

https://github.com/dlang/dmd/actions/runs/7376357253/job/20069039989
https://github.com/dlang/dmd/actions/runs/7376357253/job/20069040050
https://github.com/dlang/dmd/actions/runs/7376357242/job/20069040244

../dmd/generated/windows/release/64/dmd.exe -c  -conf= -I../dmd/druntime/import  -w -de -preview=dip1000 -preview=dtorfields -preview=fieldwise -m64  -O -release -P=-Ietc/c/zlib -ofgenerated/windows/release/64/etc/c/zlib/compress.obj etc/c/zlib/compress.c
Error: Error: C preprocess command C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe failed for file etc\c\zlib\compress.c, exit status 2

C preprocess command C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\cl.exe failed for file etc\c\zlib\adler32.c, exit status 2

etc\c\zlib\compress.c: fatal error C1083: Cannot open include file: '../dmd/druntime/import\importc.h': No such file or directory
make: *** [Makefile:322: generated/windows/release/64/etc/c/zlib/adler32.obj] Error 1
etc\c\zlib\adler32.c: fatal error C1083: Cannot open include file: '../dmd/druntime/import\importc.h': No such file or directory

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.

4 participants