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

Zig-build improvements: MSVC & C++ #636

Closed
wants to merge 1 commit into from
Closed

Zig-build improvements: MSVC & C++ #636

wants to merge 1 commit into from

Conversation

kassane
Copy link
Contributor

@kassane kassane commented Apr 22, 2024

closes #635

Not only does this change the build for the msvc target. It also adds support for C++ libraries.

Note: CI is now using a GH-action plugin to download (faster and more manageable) zig-tarballs.

@kassane
Copy link
Contributor Author

kassane commented Apr 22, 2024

maybe done for review.
cc: @ivmai

@ivmai
Copy link
Owner

ivmai commented Apr 25, 2024

A warning is reported about korandoru:
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: korandoru/setup-zig@v1. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

@kassane
Copy link
Contributor Author

kassane commented Apr 25, 2024

Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: korandoru/setup-zig@v1.

opened:

@ivmai
Copy link
Owner

ivmai commented Apr 26, 2024

Just for a reference: zig 0.12 support builds on Windows using MinGW or MS VC. Cygwin is not supported yet (ziglang/zig#751)

ivmai added a commit that referenced this pull request Apr 27, 2024
PR #636 (bdwgc).

* build.zig (build): Update comments (mention msvc, mention cc instead
of clang).
* build.zig [t.abi==.msvc] (build): Append
"-D _CRT_SECURE_NO_DEPRECATE" to flags; add msvc_dbg.c to source_files;
add TODO item and append "-D NO_SEH_AVAILABLE" to flags.
* build.zig [build_shared_libs && t.abi==.msvc] (build): Add TODO item
and append "-D DONT_USE_USER32_DLL" to flags.

Co-authored-by: Ivan Maidanski <[email protected]>
@ivmai
Copy link
Owner

ivmai commented Apr 27, 2024

Now I have pushed your code (with my modifications) to support msvc target - commit 5201e76.

@kassane
Copy link
Contributor Author

kassane commented Apr 27, 2024

Now I have pushed your code (with my modifications) to support msvc target - commit 5201e76.

Rebased again.

ivmai pushed a commit that referenced this pull request Apr 27, 2024
@ivmai
Copy link
Owner

ivmai commented Apr 27, 2024

All shared msvc builds seem to hang (I've not investigated it yet) - e.g. https://github.com/ivmai/bdwgc/actions/runs/8860942283/job/24332280900

@kassane
Copy link
Contributor Author

kassane commented Apr 27, 2024

Windows - cpptest build issue

MinGW_shared-lib

https://github.com/ivmai/bdwgc/actions/runs/8861871430/job/24334204783

+- run cpptest
   +- zig build-exe cpptest Debug native 4 errors
D:\a\bdwgc\bdwgc\include/gc/gc_cpp.h:342:5: error: replacement function 'operator new[]' cannot be declared 'inline'
D:\a\bdwgc\bdwgc\tests\cpp.cc:25:10: note: in file included from D:\a\bdwgc\bdwgc\tests\cpp.cc:25:
D:\a\bdwgc\bdwgc\include/gc_cpp.h:2:10: note: in file included from D:\a\bdwgc\bdwgc\include/gc_cpp.h:2:
MSVC_shared-lib

https://github.com/ivmai/bdwgc/actions/runs/8861871430/job/24334206851

test
+- run cpptest
   +- zig build-exe cpptest Debug native-native-msvc 20 errors
error: lld-link: undefined symbol: __declspec(dllimport) GC_set_all_interior_pointers
    note: referenced by D:\a\bdwgc\bdwgc\tests\cpp.cc:311
    note:               D:\a\bdwgc\bdwgc\zig-cache\o\fc2798597c3554acc98a525408f97dc1\cpp.obj:(WinMain)
error: lld-link: undefined symbol: __declspec(dllimport) GC_init
    note: referenced by D:\a\bdwgc\bdwgc\tests\cpp.cc:318
    note:               D:\a\bdwgc\bdwgc\zig-cache\o\fc2798597c3554acc98a525408f97dc1\cpp.obj:(WinMain)
error: lld-link: undefined symbol: __declspec(dllimport) GC_enable_incremental
    note: referenced by D:\a\bdwgc\bdwgc\tests\cpp.cc:321

@kassane kassane requested a review from ivmai April 28, 2024 17:06
ivmai added a commit that referenced this pull request Apr 30, 2024
PR #636 (bdwgc).

This commit adds support of enable_cplusplus and
enable_throw_bad_alloc_library options to Zig script (to match that
of CMake script).

* build.zig (build): Define enable_cplusplus and
enable_throw_bad_alloc_library consts (options); remove relevant TODO
items; define gccpp and gctba variables.
* build.zig [enable_cplusplus && enable_werror && (build_shared_libs
&& t.os.tag==.windows || t.abi==.msvc)] (build): Append
-Wno-inline-new-delete to flags; add comment item.
* build.zig [enable_cplusplus && enable_werror && t.abi==.msvc]
(build): Append -Wno-unused-command-line-argument to flags; add TODO
item.
* build.zig [enable_cplusplus && build_shared_libs] (build): Set gccpp
to addSharedLibrary().
* build.zig [enable_cplusplus] (build): Define gccpp_src_files
variable; specify source files and dependency library for gccpp using
linkLibCpp(); install gccpp artifact; call addTestExt() for cpptest.
* build.zig [enable_cplusplus && enable_throw_bad_alloc_library]
(build): Define gctba_src_files variable; specify source files and
dependency library for gctba using linkLibCpp(); install gctba
artifact.
* build.zig [install_headers && enable_cplusplus] (build): Install
gccpp headers.
* build.zig [install_headers && enable_cplusplus
&& enable_throw_bad_alloc_library] (build): Install gctba headers (same
as for gccpp).
* build.zig (linkLibCpp): New function (to workaround C++ library
linking by MS VC).

Co-authored-by: Ivan Maidanski <[email protected]>
ivmai pushed a commit that referenced this pull request Apr 30, 2024
@ivmai
Copy link
Owner

ivmai commented Apr 30, 2024

I've changed your commit so that the script part which build gccpp/tba looks close to that of cmake script. Merged.

@ivmai
Copy link
Owner

ivmai commented Apr 30, 2024

However there issues with cross-compilation:

@ivmai
Copy link
Owner

ivmai commented Apr 30, 2024

Also, shared lib build by MS VC hangs, e.g.
https://github.com/ivmai/bdwgc/actions/runs/8890197137/job/24409869526
Could you please figure out what's wrong? (probably an error message is displayed and this causes a hang of the job)

@ivmai
Copy link
Owner

ivmai commented Apr 30, 2024

Keeping this PR open because of the above 3 items.

@kassane
Copy link
Contributor Author

kassane commented Apr 30, 2024

However there issues with cross-compilation:

* "error: ld.lld: relocation R_MIPS_32 cannot be used against local symbol; recompile with -fPIC" -  https://github.com/ivmai/bdwgc/actions/runs/8885055838/job/24395538923

can pass -Wl,-z,notext to the linker.

@kassane
Copy link
Contributor Author

kassane commented Apr 30, 2024

* "error: ld.lld: relocation refers to a discarded section: .text.__clang_call_terminate" - https://github.com/ivmai/bdwgc/actions/runs/8885055838/job/24395545647

I'll test on powerpc64/debian (docker).

zig: add build-lib c++ & tba support
ci: C++ test
ci: msvc enable_werror falsed
zig issue - warn to error: argument unused during compilation: '-nostdinc++'
@ivmai
Copy link
Owner

ivmai commented May 2, 2024

can pass -Wl,-z,notext to the linker.

It seems it does work. It would be nice if you manage to prepare workaround. (Alternative we could turn off checking such configs for now.)

@ivmai
Copy link
Owner

ivmai commented May 2, 2024

"error: ld.lld: relocation refers to a discarded section: .text.__clang_call_terminate" - https://github.com/ivmai/bdwgc/actions/runs/8885055838/job/24395545647

Related: ziglang/zig-bootstrap#113

@kassane
Copy link
Contributor Author

kassane commented May 2, 2024

I'll test on powerpc64/debian (docker).


Related: ziglang/zig-bootstrap#113

Yes! Unfortunately, ppc64 (not ppc64le) images with no clang & libc++ to run some tests are even worse.
The tarball of the llvm17.0.1 release for ibm/aix is broken. This would be used in comparison to zig-toolchain in tests.

@ivmai
Copy link
Owner

ivmai commented May 2, 2024

Okay, I will exclude C++ shared builds on CI for these targets (mips, ppc).

@ivmai
Copy link
Owner

ivmai commented May 2, 2024

Also, shared lib build by MS VC hangs, e.g. https://github.com/ivmai/bdwgc/actions/runs/8890197137/job/24409869526

Hmm. It does not hang if -Dbuild_cord=false
I've created issue #640

@ivmai
Copy link
Owner

ivmai commented May 3, 2024

I'm closing this PR because the above mentioned issue does not depend on C++ part.

@ivmai ivmai closed this May 3, 2024
ivmai added a commit that referenced this pull request May 3, 2024
@ivmai
Copy link
Owner

ivmai commented May 3, 2024

Hmm. Some non-MSVC build for Windows also hang: issue #641

@kassane kassane deleted the zig-msvc branch May 3, 2024 12:38
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.

zig-msvc target error: 'unistd.h' file not found
2 participants