3
3
4
4
def _ispc_cc_library_impl (ctx ):
5
5
info = ctx .toolchains ["@rules_ispc//tools:toolchain_type" ].ispc_info
6
+ default_target = info .default_target
6
7
default_target_os = info .default_target_os
8
+ default_arch = info .default_arch
7
9
ispc_path = info .ispc_path
8
10
9
- generated_header_filename = ctx .attr .generated_header_filename
10
-
11
11
ispc_defines_list = ""
12
12
if len (ctx .attr .defines ) > 0 :
13
13
ispc_defines_list = "-D" + " -D" .join (ctx .attr .defines )
14
14
15
15
srcs = ctx .files .srcs
16
- inputs = depset (srcs ) # see https://bazel.build/extending/rules
16
+ inputs = depset (srcs )
17
17
18
18
object = ctx .actions .declare_file (ctx .attr .name + ".o" )
19
-
20
- o2 = ctx .actions .declare_file ("square.h" )
21
-
19
+
22
20
args = ctx .actions .args ()
23
21
24
22
if len (ctx .attr .defines ) > 0 :
25
23
args .add (ispc_defines_list )
26
24
25
+ args .add ("--target=%s" % default_target )
27
26
args .add ("--target-os=%s" % default_target_os )
28
-
29
- if default_target_os == "windows" :
30
- args .add ("--arch=x86-64" )
31
- args .add ("--target=avx2" )
32
- else :
33
- args .add ("--arch=aarch64" )
34
- args .add ("--target=neon" )
35
-
27
+ args .add ("--arch=%s" % default_arch )
36
28
args .add ("--addressing=64" )
37
29
38
30
if default_target_os != "windows" :
39
- args .add ("--pic" )
40
-
31
+ args .add ("--pic" )
32
+
41
33
args .add (ctx .file .ispc_main_source_file .short_path )
42
- #args.add(ctx.attr.ispc_main_source_file.package + ctx.attr.ispc_main_source_file)
43
-
44
- args .add ("--header-outfile=%s" % "defines/square.h" ) #generated_header_filename.short_path)
34
+ args .add ("--header-outfile=%s" % ctx .outputs .out .path )
45
35
args .add ("-o" , object )
46
36
47
37
exec_requirements = {}
@@ -50,7 +40,7 @@ def _ispc_cc_library_impl(ctx):
50
40
51
41
ctx .actions .run (
52
42
inputs = inputs ,
53
- outputs = [object , ctx .outputs .generated_header_filename ],
43
+ outputs = [object , ctx .outputs .out ],
54
44
arguments = [args ],
55
45
executable = ispc_path ,
56
46
execution_requirements = exec_requirements ,
@@ -66,7 +56,7 @@ ispc_library2 = rule(
66
56
67
57
This rule uses a precompiled version of ISPC v1.19.0 for compilation.""" ,
68
58
attrs = {
69
- "generated_header_filename " : attr .output (
59
+ "out " : attr .output (
70
60
doc = """
71
61
Name of the generated header file.
72
62
""" ,
@@ -93,13 +83,14 @@ This rule uses a precompiled version of ISPC v1.19.0 for compilation.""",
93
83
toolchains = ["@rules_ispc//tools:toolchain_type" ],
94
84
)
95
85
96
- def ispc_cc_library2 (name , generated_header_filename , ispc_main_source_file , srcs , defines = [], ** kwargs ):
86
+ def ispc_cc_library (name , out , ispc_main_source_file , srcs , defines = [], ** kwargs ):
97
87
ispc_library2 (
98
88
name = "%s_ispc_gen" % name ,
99
- generated_header_filename = generated_header_filename ,
89
+ out = out ,
100
90
ispc_main_source_file = ispc_main_source_file ,
101
91
srcs = srcs ,
102
92
defines = defines ,
93
+ tags = ["local" ],
103
94
** kwargs
104
95
)
105
96
native .cc_library (
@@ -109,35 +100,3 @@ def ispc_cc_library2(name, generated_header_filename, ispc_main_source_file, src
109
100
defines = defines ,
110
101
** kwargs
111
102
)
112
-
113
- def ispc_cc_library (name , out , ispc_main_source_file , srcs , defines = [], ** kwargs ):
114
- generated_header_filename = out
115
-
116
- ispc_defines_list = ""
117
- if len (defines ) > 0 :
118
- ispc_defines_list = "-D" + " -D" .join (defines )
119
-
120
- native .genrule (
121
- name = "%s_ispc_gen" % name ,
122
- srcs = srcs ,
123
- outs = [name + ".o" , generated_header_filename ],
124
- cmd = select ({
125
- "@platforms//os:linux" : "$(location @ispc_linux_x86_64//:ispc) %s --target=avx2 --target-os=linux --arch=x86-64 --addressing=64 --pic $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_defines_list , ispc_main_source_file , generated_header_filename , name ),
126
- "@rules_ispc//:osx_arm64" : "$(location @ispc_osx_arm64//:ispc) %s --target=neon --target-os=macos --arch=aarch64 --addressing=64 --pic $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_defines_list , ispc_main_source_file , generated_header_filename , name ),
127
- "@rules_ispc//:osx_x86_64" : "$(location @ispc_osx_x86_64//:ispc) %s --target=sse2 --target-os=macos --arch=x86-64 --addressing=64 --pic $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_defines_list , ispc_main_source_file , generated_header_filename , name ),
128
- "@platforms//os:windows" : "$(location @ispc_windows_x86_64//:ispc) %s --target=avx2 --target-os=windows --arch=x86-64 --addressing=64 $(locations %s) --header-outfile=$(location %s) -o $(location %s.o)" % (ispc_defines_list , ispc_main_source_file , generated_header_filename , name ),
129
- }),
130
- tools = select ({
131
- "@platforms//os:linux" : ["@ispc_linux_x86_64//:ispc" ],
132
- "@rules_ispc//:osx_arm64" : ["@ispc_osx_arm64//:ispc" ],
133
- "@rules_ispc//:osx_x86_64" : ["@ispc_osx_x86_64//:ispc" ],
134
- "@platforms//os:windows" : ["@ispc_windows_x86_64//:ispc" ],
135
- }),
136
- )
137
- native .cc_library (
138
- name = name ,
139
- srcs = [name + ".o" ],
140
- hdrs = [name + ".h" ],
141
- defines = defines ,
142
- ** kwargs
143
- )
0 commit comments