-
Notifications
You must be signed in to change notification settings - Fork 77
upgrade to zig 0.14.0 #203
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
base: main
Are you sure you want to change the base?
Conversation
|
Hit compilation errors which indicate that threads weren't turned on, when doing More similar errors around pthreads when using 0.14 nightlies (e.g. 0.14.0-dev.2271+f845fa04a) such as: Maybe related to ziglang/zig#10989 (comment) ? |
|
I just want to drop by to say thank you, @chrisirhc! I adapted your existing PR and got a lot further in using Zig as a C/C++ toolchain on Windows (and only Windows - where getting a C/C++ environment set up is just ...blergh). Please find my patch below - using it, I could continue until I hit ziglang/zig#23233 :-) I needed 0.14.0 because pthreads.h was added to msys2 after 0.13.0 and I could not get through abseil without it. If you want to use it, please do - I disclaim any copyright, this is just a minor change to what you did. |
|
@ah-quant Thanks for sharing your patch! Maybe time to test this again now that zig 0.14 has some partial fixes to ziglang/zig#21721 |
b4ab950 to
6fd5738
Compare
toolchain/private/defs.bzl
Outdated
| "libc/include/generic-musl", | ||
| "libc/wasi", | ||
| ] + _INCLUDE_TAIL, | ||
| linkopts = [], | ||
| dynamic_library_linkopts = [], | ||
| supports_dynamic_linker = False, | ||
| copts = [], | ||
| copts = [ | ||
| "-D_LIBCPP_HAS_MUSL_LIBC", | ||
| "-D_LIBCPP_HAS_NO_THREADS", | ||
| "-D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS", | ||
| "-D_LIBCPP_HAS_NO_THREAD_API_PTHREAD", | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempt to resolve issue:
external/_main~toolchains~zig_config/lib/libc/include/wasm-wasi-musl/stdio.h:8:10: fatal error: 'features.h' file not found
Output from claude 3.5:
I've made the following changes to fix the WASI target configuration:
Added additional include paths:
libc/include/generic-musl - For generic musl libc headers
libc/include/any-wasi-any - For WASI-specific headers
Added compiler flags:
-D_LIBCPP_HAS_MUSL_LIBC - To indicate we're using musl libc
-D_LIBCPP_HAS_NO_THREADS - WASI doesn't support threading
-D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS - Disable thread-unsafe functions
-D_LIBCPP_HAS_NO_THREAD_API_PTHREAD - Disable pthread API since WASI doesn't support it
These changes should:
Ensure the compiler can find the necessary libc headers
Configure libc++ to work in a single-threaded WASI environment
Prevent pthread-related errors since WASI doesn't support threading
Try running the test again with these changes. The compiler should now be able to find the necessary headers and properly handle the WASI target configuration.
I removed libc/include/any-wasi-any since that doesn't exist, but the other changes seem to fix the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing all the additional copts led to the tests passing, so I removed them but kept the additional generic-musl includes.
toolchain/private/defs.bzl
Outdated
| copts = [ | ||
| "-D_GNU_SOURCE", | ||
| "-D_POSIX_C_SOURCE=200809L", | ||
| "-D_XOPEN_SOURCE=600", | ||
| ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempt to resolve issue:
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:24:17: could not determine kind of name for C.grantpt
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:20:12: could not determine kind of name for C.posix_openpt
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:32:26: could not determine kind of name for C.ptsname
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:28:17: could not determine kind of name for C.unlockpt
Output from Claude 3.5:
I've added three important feature test macros to the Linux GNU target configuration:
-D_GNU_SOURCE - Enables all GNU extensions
-D_POSIX_C_SOURCE=200809L - Enables POSIX.1-2008 features
-D_XOPEN_SOURCE=600 - Enables X/Open System Interface (XSI) features
These macros should make the necessary POSIX terminal functions (grantpt, posix_openpt, ptsname, unlockpt) available to CGo when building the Go standard library.
The error occurred because these functions are part of the POSIX terminal interface, and they need to be explicitly enabled through feature test macros when building with certain C library implementations.
It does seem to fix the issue above, but introduces new warnings:
INFO: From GoStdlib external/rules_go~0.45.1/stdlib_/pkg:
# internal/testpty
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:10:9: warning: '_XOPEN_SOURCE' macro redefined [-Wmacro-redefined]
10 | #define _XOPEN_SOURCE 600
| ^
./external/_main~toolchains~zig_sdk-macos-amd64/tools/x86_64-linux-gnu.2.28/../../lib/libc/include/generic-glibc/features.h:236:10: note: previous definition is here
236 | # define _XOPEN_SOURCE 700
| ^
1 warning generated.
# net
bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/net/cgo_unix_cgo.go:10:9: warning: '_GNU_SOURCE' macro redefined [-Wmacro-redefined]
10 | #define _GNU_SOURCE
| ^
<command line>:13:9: note: previous definition is here
13 | #define _GNU_SOURCE 1
| ^
1 warning generated.
INFO: From GoStdlib external/rules_go~0.45.1/stdlib_/pkg:
# internal/testpty
bazel-out/darwin_x86_64-fastbuild-ST-1a3e3e752a28/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:10:9: warning: '_XOPEN_SOURCE' macro redefined [-Wmacro-redefined]
10 | #define _XOPEN_SOURCE 600
| ^
./external/_main~toolchains~zig_sdk-macos-amd64/tools/x86_64-linux-gnu.2.28/../../lib/libc/include/generic-glibc/features.h:236:10: note: previous definition is here
236 | # define _XOPEN_SOURCE 700
| ^
1 warning generated.
# net
bazel-out/darwin_x86_64-fastbuild-ST-1a3e3e752a28/bin/external/rules_go~0.45.1/stdlib_/src/net/cgo_unix_cgo.go:10:9: warning: '_GNU_SOURCE' macro redefined [-Wmacro-redefined]
10 | #define _GNU_SOURCE
| ^
<command line>:13:9: note: previous definition is here
13 | #define _GNU_SOURCE 1
| ^
1 warning generated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all except for -D_GNU_SOURCE led to the tests passing, so I removed them.
|
Failure is due to missing ziglang mirror, see bazelbuild/bazel#25575 . Will retry after that has landed. |
fe9b182 to
5681445
Compare
> The error is coming from Go's CGo trying to build the standard library with the Zig C++ compiler, and it's failing to find certain POSIX terminal functions (grantpt, posix_openpt, ptsname, unlockpt). ``` bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:24:17: could not determine kind of name for C.grantpt bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:20:12: could not determine kind of name for C.posix_openpt bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:32:26: could not determine kind of name for C.ptsname bazel-out/darwin_x86_64-fastbuild-ST-1dd79e0b6a44/bin/external/rules_go~0.45.1/stdlib_/src/internal/testpty/pty_cgo.go:28:17: could not determine kind of name for C.unlockpt ```
-D_GNU_SOURCE - Enables all GNU extensions -D_POSIX_C_SOURCE=200809L - Enables POSIX.1-2008 features -D_XOPEN_SOURCE=600 - Enables X/Open System Interface (XSI) features These macros should make the necessary POSIX terminal functions (grantpt, posix_openpt, ptsname, unlockpt) available to CGo when building the Go standard library. The error occurred because these functions are part of the POSIX terminal interface, and they need to be explicitly enabled through feature test macros when building with certain C library implementations.
5681445 to
81dfbf9
Compare
| "error spawning {s}: {s}\n", | ||
| .{ params.args.items[0], @errorName(err) }, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From new version of zig's zig fmt.
|
Do not land. Blocked on ziglang/zig#23287 based on internal testing. |
|
I ran into this with trying to set up something hermetic for Windows just to get rules_java working, and VS just isn't an option for us. |
|
I'm running into some integration issues between Zig 0.14 and on arm64. I wonder a bit if the afore-linked ziglang/zig#21721 will eventually catch this, or if it's something specific to my setup. |
Disclaimer: No idea what I'm doing.