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: update to 0.13.0 #24430

Closed
wants to merge 1 commit into from
Closed

zig: update to 0.13.0 #24430

wants to merge 1 commit into from

Conversation

i0ntempest
Copy link
Member

Description

Type(s)
  • bugfix
  • enhancement
  • security fix
Tested on

macOS x.y
Xcode x.y / Command Line Tools x.y.z

Verification

Have you

  • followed our Commit Message Guidelines?
  • squashed and minimized your commits?
  • checked that there aren't other open pull requests for the same change?
  • referenced existing tickets on Trac with full URL in commit message?
  • checked your Portfile with port lint --nitpick?
  • tried existing tests with sudo port test?
  • tried a full install with sudo port -vst install?
  • tested basic functionality of all binary files?
  • checked that the Portfile's most important variants haven't been broken?

@macportsbot macportsbot added type: update maintainer: none by: member Created by a member with commit rights labels Jun 11, 2024
@i0ntempest
Copy link
Member Author

While this builds fine, zig version gives:

0.13.0
error: Zig was built/linked incorrectly: LLVM and Clang have separate copies of libc++
       If you are dynamically linking LLVM, make sure you dynamically link libc++ too

I don't know if this is caused by how MP builds LLVM and Clang, but the combiler functions and I can build ncdu port just fine.

@pmetzger
Copy link
Member

@i0ntempest I can't merge this if it's broken? What would you like to do next?

@i0ntempest
Copy link
Member Author

@i0ntempest I can't merge this if it's broken? What would you like to do next?

I don't know if it's broken. Changelog did not state changes in build processes and the resulting binary seems to be working fine. More likely it's triggered by how MP installs Clang and LLVM but I'm not sure. Maybe tag some C/C++ experts we have here to take a look?

@pmetzger
Copy link
Member

@jmroot @ryandesign Who would be good at looking at this do you think?

@ryandesign
Copy link
Contributor

I don't know. Ask the developers of zig what their error message means and how they would like us to fix it.

@pmetzger
Copy link
Member

@i0ntempest How would you like to proceed?

@i0ntempest
Copy link
Member Author

I opened an upstream issue, hopefully they can provide an explanation. Meanwhile I have pushed 0.12.1.

@reneeotten
Copy link
Contributor

ping - please fix or close until upstream has responded

@i0ntempest
Copy link
Member Author

We had a response but the exact problem isn't clear yet. They said I "somehow have two libc++ libraries loaded into the Zig compiler process".

@sugarthc
Copy link

sugarthc commented Aug 21, 2024

The issue appears to be that in 0.13.0, libClang-cpp and libLLVM are linked dynamically, where they were not in 0.12.1. Those libraries in turn link the system libc++ library, also dynamically. The zig executable, however, links libc++ statically and it is not clear which libc++ it is linking, but zig itself is detecting a mismatch and throwing the error above.

Much seems to have changed with the build between the two releases and it is not clear to me where these changes are being introduced. I'm not well versed in cmake and I certainly have next to no understanding of the zig build system. The interaction between the two seems rather nightmarish to me.

It seems to be the confluence of changes in the llvm/clang cmake files and very minor changes in zig build files. I wish I could tell which changes but at this point I cannot. I will keep looking, though.

The bottom line (I think) is that either llvm and clang need to be statically linked as they were in 0.12.1 (which I think triggers a change in which libc++ is linked) or the stage3 zig binary needs to link the system libc++ dynamically. I don't know how to effect either of these changes at the moment.

The net effect of the former is that zig goes back to being an approximately 180MB binary with the macports llvm/clang as build-only dependencies or, for the latter, zig is a 20-ish MB binary that has macports llvm/clang as runtime dependencies.

@sugarthc
Copy link

sugarthc commented Aug 21, 2024

I poked at this a bit more and have found that adding the following to the Portfile appears to reproduce what was happening with the 0.12.1 port. That is to say that the zig binary statically links llvm/clang and (some) libc++. I'm not sure if it's the system one (probably not) or the one in llvm or zig's own. In any case this produces a 184MB zig binary (same as the previous version) that no longer emits the error above.

configure.args-append -DZIG_STATIC_LLVM=ON

I still have no idea why this is needed to reproduce the default behavior from the previous release. I've spotted no diffs in either llvm/clang or zig that points specifically to this. I'm guessing something to do with library detection in the new cmake files in llvm/clang. If somebody discovers this I'd love to hear about it.

@sugarthc
Copy link

I’d also like to reiterate that neither the previous version nor this one with this change applied requires llvm or clang as dependencies unless you are building from source, so it’d be nice if the clang dependency could be moved to depends_build

@sugarthc
Copy link

sugarthc commented Aug 21, 2024

To this point I can see no clear path forward for dynamic linking of llvm/clang AND libc++ in zig itself. I found this upstream PR that seems to want to accomplish this but it was closed without merging. Apparently because nobody could be bothered to rebase the patch.

@sugarthc sugarthc mentioned this pull request Aug 29, 2024
12 tasks
@i0ntempest i0ntempest closed this Aug 30, 2024
@i0ntempest i0ntempest deleted the zig branch August 30, 2024 02:35
i0ntempest pushed a commit that referenced this pull request Aug 30, 2024
    - Update to version 0.13.0
    - Force static linking of llvm/clang; this was the default previously
    - Since llvm/clang are linking statically these can be build-only dependencies.

    Closes: https://trac.macports.org/ticket/70584
    Supersedes: #24430
@carlocab
Copy link

carlocab commented Mar 16, 2025

Should be fixed upstream in ziglang/zig#23264. See also discussion at Homebrew/homebrew-core#210173.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
by: member Created by a member with commit rights maintainer: none type: update
Development

Successfully merging this pull request may close these issues.

7 participants