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

macOS build from master can't find libs when using symlinked zig binary #1117

Closed
binary132 opened this Issue Jun 15, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@binary132

binary132 commented Jun 15, 2018

Platform

  • macOS 10.13.5
  • cmake 3.11.4

Steps to build and link

I cloned and built Zig using ninja, via cmake -G Ninja .. -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm@6/, ninja build, and ninja install. This installed the zig libs into the build-local path. I was also able to build stage2 zig using the newly built zig binary.

I then created a symlink to the newly built stage1 zig binary in my user's PATH.

Unexpected output

When I run zig build-exe hello.zig on the sample Hello World, the following message appears:

Unable to find zig lib directory

Workarounds

When I run <build path>/bin/zig build-exe hello.zig on the sample Hello World, it compiles successfully.

I can also use the Zig installed from Homebrew successfully, and I can use the Ubuntu build too.

I am also able to make this work by checking out, building, and installing 0.2.0, because it installs the libs to /usr/local/lib/zig. However, linking the master build's build/libs/zig into /usr/local/lib/zig does not work.

@andrewrk andrewrk added the bug label Jun 15, 2018

@andrewrk andrewrk added this to the 0.3.0 milestone Jun 15, 2018

@andrewrk

This comment has been minimized.

Member

andrewrk commented Jun 15, 2018

I think this can be solved by calling realpath after _NSGetExecutablePath here:

zig/src/os.cpp

Line 996 in b3a3e20

int ret2 = _NSGetExecutablePath(buf_ptr(out_path), &u32_len);

binary132 pushed a commit to binary132/zig that referenced this issue Jun 17, 2018

Bodie Solomon
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: ziglang#1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looked in its relative path,
which caused a symlinked Zig to be unable to find the stdlib.

This patch fixes the issue by resolving the relative path to the real
path using _realpath()_ before copying to the output path.

binary132 pushed a commit to binary132/zig that referenced this issue Jun 18, 2018

Bodie Solomon
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: ziglang#1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looks in its relative path,
which causes a symlinked Zig to be unable to find the stdlib.

This patch fixes the issue by resolving the relative path to the real
path using realpath() before copying the result to the output path.

binary132 pushed a commit to binary132/zig that referenced this issue Jun 18, 2018

Bodie Solomon
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: ziglang#1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looks in its relative path,
which causes a symlinked Zig to be unable to find the stdlib.

This patch fixes the issue by resolving the relative path to the real
path using realpath() before copying the result to the output path.
@binary132

This comment has been minimized.

binary132 commented Jun 18, 2018

Ok, this pull request does the trick and is ISO C++ compliant.

binary132 pushed a commit to binary132/zig that referenced this issue Jun 18, 2018

Bodie Solomon
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: ziglang#1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looks in its path as returned
by _NSGetExecutablePath, which may be a symlink.  This means that a
symlinked Zig cannot find the Zig stdlib.

This patch fixes the issue by resolving the _NSGetExecutablePath result
to the real path using realpath() before copying the result to the
output path.

binary132 pushed a commit to binary132/zig that referenced this issue Jun 18, 2018

Bodie Solomon
Fix 1117: Use realpath in stage1 Darwin os_self_exe_path
Issue: ziglang#1117

The macOS stage1 Zig compiler should look in Zig's real absolute path
for the Zig stdlib, but os_self_exe_path looks in its path as returned
by _NSGetExecutablePath, which may be a symlink.  This means that a
symlinked Zig cannot find the Zig stdlib.

This patch fixes the issue by resolving the _NSGetExecutablePath result
to the real path using realpath() before copying the result to the
output path.
@andrewrk

This comment has been minimized.

Member

andrewrk commented Jun 18, 2018

Thanks for the PR!

@andrewrk andrewrk closed this Jun 18, 2018

@binary132

This comment has been minimized.

binary132 commented Aug 6, 2018

@andrewrk this isn't fixed in the stage2 compiler. Where should I start?

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