/
assembler.ex
61 lines (50 loc) · 1.28 KB
/
assembler.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
defmodule Zig.Assembler do
@moduledoc """
Assembles the staging directory for zig content.
The staging directory contains:
- `build.zig` for the library file.
"""
alias Zig.Builder
@doc "staging directory for the zigler assembly"
def directory(module) do
Path.join(System.tmp_dir(), to_string(module))
end
def assemble(module, opts) do
directory = directory(module)
File.mkdir_p!(directory)
opts =
Keyword.take(opts, [
:to,
:from,
:link_lib,
:build_opts,
:stage1,
:include_dir,
:c_src,
:packages,
:local_zig
])
opts = Keyword.merge([to: directory], opts)
opts =
if Keyword.has_key?(opts, :link_lib) do
Keyword.put(opts, :link_lib, adjust_link_lib(opts[:link_lib], opts[:from]))
end
# Enum.each(opts[:link_lib], fn
# {:system, _} -> :pass
# lib ->
# target = Path.join(opts[:to], lib)
# unless File.exists?(target) do
# opts[:from]
# |> Path.join(lib)
# |> File.ln_s!(target)
# end
# end)
Builder.build(module, opts)
end
defp adjust_link_lib(link_lib, from) do
Enum.map(link_lib, fn
{:system, _} = system -> system
lib -> Path.expand(lib, from)
end)
end
end