@@ -46,7 +46,9 @@ and even simple programs will not compile without them.
46
46
function generate_compiler_wrappers! (platform:: Platform ; bin_path:: AbstractString ,
47
47
host_platform:: Platform = Linux (:x86_64 ; libc= :musl ),
48
48
rust_platform:: Platform = Linux (:x86_64 ; libc= :glibc ),
49
- compilers:: Vector{Symbol} = [:c ])
49
+ compilers:: Vector{Symbol} = [:c ],
50
+ allow_unsafe_flags:: Bool = false ,
51
+ )
50
52
global use_ccache
51
53
52
54
# Wipe that directory out, in case it already had compiler wrappers
@@ -66,7 +68,8 @@ function generate_compiler_wrappers!(platform::Platform; bin_path::AbstractStrin
66
68
hash_args:: Bool = false ,
67
69
extra_cmds:: String = " " ,
68
70
link_only_flags:: Vector = String[],
69
- env:: Dict{String,String} = Dict {String,String} ())
71
+ env:: Dict{String,String} = Dict {String,String} (),
72
+ unsafe_flags = String[])
70
73
write (io, """
71
74
#!/bin/bash
72
75
# This compiler wrapper script brought into existence by `generate_compiler_wrappers()`
@@ -109,6 +112,16 @@ function generate_compiler_wrappers!(platform::Platform; bin_path::AbstractStrin
109
112
write (io, " export $(name) =\" $(val) \"\n " )
110
113
end
111
114
115
+ if length (unsafe_flags) >= 1
116
+ write (io, """
117
+ if [[ \"\$ @\" =~ \" $(join (unsafe_flags, " \" |\" " )) \" ]]; then
118
+ echo -e \" You used one or more of the unsafe flags: $(join (unsafe_flags, " , " )) \\ nPlease repent.\" >&2
119
+ exit 1
120
+ fi
121
+ """ )
122
+ println (io)
123
+ end
124
+
112
125
if allow_ccache
113
126
write (io, """
114
127
if [ \$ {USE_CCACHE} == "true" ]; then
@@ -213,9 +226,9 @@ function generate_compiler_wrappers!(platform::Platform; bin_path::AbstractStrin
213
226
end
214
227
215
228
# C/C++/Fortran
216
- gcc (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -gcc $(gcc_flags (p)) " ; hash_args= true , link_only_flags= gcc_link_flags (p))
217
- gxx (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -g++ $(gcc_flags (p)) " ; hash_args= true , link_only_flags= gcc_link_flags (p))
218
- gfortran (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -gfortran $(fortran_flags (p)) " ; allow_ccache= false )
229
+ gcc (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -gcc $(gcc_flags (p)) " ; hash_args= true , link_only_flags= gcc_link_flags (p), unsafe_flags = allow_unsafe_flags ? String[] : [ " -Ofast " , " -ffast-math " , " -funsafe-math-optimizations " ] )
230
+ gxx (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -g++ $(gcc_flags (p)) " ; hash_args= true , link_only_flags= gcc_link_flags (p), unsafe_flags = allow_unsafe_flags ? String[] : [ " -Ofast " , " -ffast-math " , " -funsafe-math-optimizations " ] )
231
+ gfortran (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(triplet (p)) /bin/$(triplet (p)) -gfortran $(fortran_flags (p)) " ; allow_ccache= false , unsafe_flags = allow_unsafe_flags ? String[] : [ " -Ofast " , " -ffast-math " , " -funsafe-math-optimizations " ] )
219
232
clang (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(host_target) /bin/clang $(clang_flags (p)) " ; link_only_flags= clang_link_flags (p))
220
233
clangxx (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(host_target) /bin/clang++ $(clang_flags (p)) " ; link_only_flags= clang_link_flags (p))
221
234
objc (io:: IO , p:: Platform ) = wrapper (io, " /opt/$(host_target) /bin/clang -x objective-c $(clang_flags (p)) " ; link_only_flags= clang_link_flags (p))
0 commit comments