@@ -32,62 +32,62 @@ def nix_wrapper(ctx, derivation, deps, nixpkgs, out):
32
32
),
33
33
)
34
34
35
- def _nix_debug_build (ctx , out_symlink ):
35
+ def _nix_debug_build (ctx , out_tree ):
36
36
toolchain = ctx .toolchains ["@io_tweag_rules_nixpkgs//:toolchain_type" ]
37
37
38
38
# <name>.path_info generates a file with the referenced nix store paths
39
39
ctx .actions .run_shell (
40
- inputs = [out_symlink ],
40
+ inputs = [out_tree ],
41
41
outputs = [ctx .outputs .path_info ],
42
42
command = "{} path-info -r {}/result > {}" .format (
43
43
toolchain .nixinfo .nix_bin_path ,
44
- out_symlink .path ,
44
+ out_tree .path ,
45
45
ctx .outputs .path_info .path ,
46
46
),
47
47
)
48
48
49
49
# <name>.log generates a file with the nix build log for this target
50
50
ctx .actions .run_shell (
51
- inputs = [out_symlink ],
51
+ inputs = [out_tree ],
52
52
outputs = [ctx .outputs .log ],
53
53
command = "{} log {}/result > {}" .format (
54
54
toolchain .nixinfo .nix_bin_path ,
55
- out_symlink .path ,
55
+ out_tree .path ,
56
56
ctx .outputs .log .path ,
57
57
),
58
58
)
59
59
60
60
# <name>.derivation shows the derivation for this target
61
61
ctx .actions .run_shell (
62
- inputs = [out_symlink ],
62
+ inputs = [out_tree ],
63
63
outputs = [ctx .outputs .derivation ],
64
64
command = "{} show-derivation {}/result > {}" .format (
65
65
toolchain .nixinfo .nix_bin_path ,
66
- out_symlink .path ,
66
+ out_tree .path ,
67
67
ctx .outputs .derivation .path ,
68
68
),
69
69
)
70
70
71
71
ctx .actions .run_shell (
72
- inputs = [out_symlink ],
72
+ inputs = [out_tree ],
73
73
outputs = [ctx .outputs .lib_list ],
74
74
command = "find {}/result/lib > {}" .format (
75
- out_symlink .path ,
75
+ out_tree .path ,
76
76
ctx .outputs .lib_list .path ,
77
77
),
78
78
)
79
79
80
- def _nix_docker_helper (ctx , out_symlink ):
80
+ def _nix_docker_helper (ctx , out_tree ):
81
81
toolchain = ctx .toolchains ["@io_tweag_rules_nixpkgs//:toolchain_type" ]
82
82
83
83
# Create a tarball with runtime dependencies of built package.
84
84
ctx .actions .run_shell (
85
- inputs = [out_symlink ],
85
+ inputs = [out_tree ],
86
86
outputs = [ctx .outputs .tar ],
87
87
command = " " .join ([
88
88
toolchain .nixinfo .nix_store_bin_path ,
89
89
"-q -R --include-outputs" ,
90
- "{}/result" .format (out_symlink .path ),
90
+ "{}/result" .format (out_tree .path ),
91
91
"|" ,
92
92
"xargs tar c" ,
93
93
">" ,
@@ -101,60 +101,14 @@ def nix_build(
101
101
srcs ,
102
102
deps ,
103
103
repo , # nix repo
104
- out_symlink ,
105
- out_include_dir ,
106
- out_include_dir_name ,
107
- out_lib_dir_name ,
108
- out_shared_libs ,
109
- out_static_libs ):
104
+ out_tree ):
110
105
""" runs nix-build on a set of sources """
111
106
toolchain = ctx .toolchains ["@io_tweag_rules_nixpkgs//:toolchain_type" ]
112
107
113
- _nix_debug_build (ctx , out_symlink ) # add optional debug outputs
114
- _nix_docker_helper (ctx , out_symlink )
108
+ _nix_debug_build (ctx , out_tree ) # add optional debug outputs
109
+ _nix_docker_helper (ctx , out_tree )
115
110
116
- if out_include_dir :
117
- ctx .actions .run_shell (
118
- inputs = [out_symlink ],
119
- outputs = [out_include_dir ],
120
- command = "cp -R {}/{}/* {}" .format (
121
- out_symlink .path ,
122
- out_include_dir_name ,
123
- out_include_dir .path ,
124
- ),
125
- )
126
-
127
- if out_shared_libs :
128
- ctx .actions .run_shell (
129
- inputs = [out_symlink ],
130
- outputs = out_shared_libs .values (),
131
- command = "\n " .join ([
132
- "cp -R {}/{}/{} {}" .format (
133
- out_symlink .path ,
134
- out_lib_dir_name ,
135
- lib_name ,
136
- out_shared_libs [lib_name ].path ,
137
- )
138
- for lib_name in out_shared_libs
139
- ]),
140
- )
141
-
142
- if out_static_libs :
143
- ctx .actions .run_shell (
144
- inputs = [out_symlink ],
145
- outputs = out_static_libs .values (),
146
- command = "\n " .join ([
147
- "cp -R {}/{}/{} {}" .format (
148
- out_symlink .path ,
149
- out_lib_dir_name ,
150
- lib_name ,
151
- out_static_libs [lib_name ].path ,
152
- )
153
- for lib_name in out_static_libs
154
- ]),
155
- )
156
-
157
- input_nix_out_symlinks = []
111
+ input_nix_out_trees = []
158
112
nix_file_deps = []
159
113
nixpath_entries = []
160
114
for dep in deps :
@@ -163,7 +117,7 @@ def nix_build(
163
117
nixpath_entries += ["-I" , "{}={}" .format (info .name , info .nix_import .path )]
164
118
nix_file_deps .append (info .nix_import )
165
119
nix_file_deps += info .extra_nix_files
166
- input_nix_out_symlinks .append (info .out_symlink )
120
+ input_nix_out_trees .append (info .out_tree )
167
121
168
122
maybe_build_attr = []
169
123
if ctx .attr .build_attribute :
@@ -173,8 +127,8 @@ def nix_build(
173
127
]
174
128
175
129
ctx .actions .run (
176
- outputs = [out_symlink ],
177
- inputs = srcs + input_nix_out_symlinks + nix_file_deps + [repo [NixPkgsInfo ].nix_import ],
130
+ outputs = [out_tree ],
131
+ inputs = srcs + input_nix_out_trees + nix_file_deps + [repo [NixPkgsInfo ].nix_import ],
178
132
executable = toolchain .nixinfo .nix_build_bin_path ,
179
133
env = {
180
134
# nix tries to update a database entry for it's cache state
@@ -191,7 +145,7 @@ def nix_build(
191
145
"--keep-failed" , # TODO(danny): when should we enable this?
192
146
"--show-trace" ,
193
147
"--out-link" ,
194
- "{}/result" .format (out_symlink .path ),
148
+ "{}/result" .format (out_tree .path ),
195
149
],
196
150
mnemonic = "NixBuild" ,
197
151
execution_requirements = {
@@ -207,6 +161,56 @@ def nix_build(
207
161
# },
208
162
)
209
163
164
+ def nix_collect_cc (
165
+ ctx ,
166
+ out_tree , # input
167
+ out_include_dir ,
168
+ out_include_dir_name ,
169
+ out_lib_dir_name ,
170
+ out_shared_libs ,
171
+ out_static_libs ):
172
+ """nix_collect_cc takes the output symlink and collects cc artifacts"""
173
+ if out_include_dir :
174
+ ctx .actions .run_shell (
175
+ inputs = [out_tree ],
176
+ outputs = [out_include_dir ],
177
+ command = "cp -R {}/{}/* {}" .format (
178
+ out_tree .path ,
179
+ out_include_dir_name ,
180
+ out_include_dir .path ,
181
+ ),
182
+ )
183
+
184
+ if out_shared_libs :
185
+ ctx .actions .run_shell (
186
+ inputs = [out_tree ],
187
+ outputs = out_shared_libs .values (),
188
+ command = "\n " .join ([
189
+ "cp -R {}/{}/{} {}" .format (
190
+ out_tree .path ,
191
+ out_lib_dir_name ,
192
+ lib_name ,
193
+ out_shared_libs [lib_name ].path ,
194
+ )
195
+ for lib_name in out_shared_libs
196
+ ]),
197
+ )
198
+
199
+ if out_static_libs :
200
+ ctx .actions .run_shell (
201
+ inputs = [out_tree ],
202
+ outputs = out_static_libs .values (),
203
+ command = "\n " .join ([
204
+ "cp -R {}/{}/{} {}" .format (
205
+ out_tree .path ,
206
+ out_lib_dir_name ,
207
+ lib_name ,
208
+ out_static_libs [lib_name ].path ,
209
+ )
210
+ for lib_name in out_static_libs
211
+ ]),
212
+ )
213
+
210
214
GENERATE_NIX_MANIFEST = """
211
215
set -euo pipefail
212
216
store_paths=()
0 commit comments