Skip to content

Commit 86a117d

Browse files
committed
fixes macos tmp drive issue by forcing symlink resolution
1 parent 13d2ebc commit 86a117d

5 files changed

Lines changed: 55 additions & 5 deletions

File tree

lib/zig.ex

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,55 @@ defmodule Zig do
738738
true
739739
end
740740
end
741+
742+
@doc false
743+
# Returns the system temporary directory with all symlinks resolved.
744+
# On macOS, /tmp and /var are symlinks to /private/tmp and /private/var,
745+
# which can cause issues with relative path resolution in Zig's build system.
746+
def _tmp_dir do
747+
tmp = System.tmp_dir()
748+
# Remove trailing slash to normalize the path
749+
tmp = String.trim_trailing(tmp, "/")
750+
resolve_symlinks(tmp)
751+
end
752+
753+
# Recursively resolve all symlinks in a path by checking each component
754+
defp resolve_symlinks(path) do
755+
# Split the path into components
756+
parts = Path.split(path)
757+
758+
# Rebuild the path, resolving symlinks at each level
759+
{resolved, _} =
760+
Enum.reduce(parts, {"", ""}, fn part, {current_path, _} ->
761+
next_path =
762+
if current_path == "" do
763+
part
764+
else
765+
Path.join(current_path, part)
766+
end
767+
768+
# Check if this component is a symlink
769+
case File.read_link(next_path) do
770+
{:ok, link_target} ->
771+
# If the link target is absolute, use it directly
772+
# Otherwise, resolve it relative to the current directory
773+
resolved_path =
774+
if String.starts_with?(link_target, "/") do
775+
link_target
776+
else
777+
Path.join(Path.dirname(next_path), link_target)
778+
end
779+
780+
{resolved_path, ""}
781+
782+
{:error, _} ->
783+
# Not a symlink, continue with the current path
784+
{next_path, ""}
785+
end
786+
end)
787+
788+
resolved
789+
end
741790
end
742791

743792
# check that the otp_version is 24 or greater.

lib/zig/builder.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ after
3232
def staging_directory(module) do
3333
staging_root =
3434
case System.get_env("ZIGLER_STAGING_ROOT", "") do
35-
"" -> System.tmp_dir()
35+
"" -> Zig._tmp_dir()
3636
path -> path
3737
end
3838

@@ -121,7 +121,7 @@ after
121121
# The staging root should already exist - we only create the module-specific subdirectory
122122
staging_root =
123123
case System.get_env("ZIGLER_STAGING_ROOT", "") do
124-
"" -> System.tmp_dir()
124+
"" -> Zig._tmp_dir()
125125
path -> path
126126
end
127127

lib/zig/compiler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ defmodule Zig.Compiler do
218218
## STEPS
219219

220220
def assembly_dir(env, module) do
221-
System.tmp_dir()
221+
Zig._tmp_dir()
222222
|> String.replace("\\", "/")
223223
|> Path.join(".zigler_compiler/#{env}/#{module}")
224224
end

lib/zig/sema.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ defmodule Zig.Sema do
664664
16
665665
|> :crypto.strong_rand_bytes()
666666
|> Base.encode16(case: :lower)
667-
|> then(&Path.join(System.tmp_dir!(), &1))
667+
|> then(&Path.join(Zig._tmp_dir(), &1))
668668

669669
File.touch!(tmp_path)
670670

@@ -692,7 +692,7 @@ defmodule Zig.Sema do
692692
16
693693
|> :crypto.strong_rand_bytes()
694694
|> Base.encode16(case: :lower)
695-
|> then(&Path.join(System.tmp_dir!(), &1))
695+
|> then(&Path.join(Zig._tmp_dir(), &1))
696696

697697
case System.cmd("objcopy", ["--dump-section", ".sema=#{tmp_path}", file]) do
698698
{_, 0} ->

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
1010
"pegasus": {:hex, :pegasus, "0.2.6", "b4af6522326fbb2ffd1bb706e78ec05854fbcb4b03a7fe08f8db2e9de1d0be67", [:mix], [{:nimble_parsec, "~> 1.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0ac159f0ccab7967cf90208327cc8a35788874814c8d78e19d47104d3fc049b9"},
1111
"protoss": {:hex, :protoss, "1.1.0", "853533313989751c7da5b0e1ce71501a23f3dc41f128709478af40daccc6e959", [:mix], [], "hexpm", "c2f874383dd047fcfdf467b814dd33a208a4d24a467aef90d86185b41a0752ad"},
12+
"zexplorer": {:git, "https://github.com/ndrean/zexplorer", "39ccd2087657eb50dffce703007bb6a1a4988dc2", []},
1213
"zig_doc": {:hex, :zig_doc, "0.5.0", "2bd2e70190b3c2cdbe7f0b0172a3d2d776cf92096b5f51b8f9131d15ccc9eeeb", [:mix], [{:ex_doc, "~> 0.34.2", [hex: :ex_doc, repo: "hexpm", optional: false]}, {:zig_parser, "~> 0.5", [hex: :zig_parser, repo: "hexpm", optional: false]}], "hexpm", "c4769bcc4d7d18cb4bfbff238100e80b9e514021f5dd818645cfe7ff2ea405c0"},
1314
"zig_get": {:hex, :zig_get, "0.15.2", "a6ccaa894213839ba95615bf9be2b2c9268e37ab9547a2344830202cfd6d7cc0", [:mix], [], "hexpm", "e6b0028f2d5a8da791ff8037deff5b492784017d8d241e598377a24bd765f56f"},
1415
"zig_parser": {:hex, :zig_parser, "0.6.0", "b1296c64bf5c2592de2eb4bc8bbf79d85b1d6a3ab444c443becd7af579d85681", [:mix], [{:pegasus, "~> 0.2.4", [hex: :pegasus, repo: "hexpm", optional: false]}], "hexpm", "bb7a1523b69f7f8f6b74ba5bf9dabc83f512c0cd67d9eebba1c501a529a2f95e"},

0 commit comments

Comments
 (0)