Skip to content

Commit 817a366

Browse files
committed
use better defaults for march and cpu target (#105)
1 parent 5df4211 commit 817a366

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/PackageCompiler.jl

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,22 @@ export create_sysimage, create_app, audit_app, restore_default_sysimage
1010
include("juliaconfig.jl")
1111

1212
const NATIVE_CPU_TARGET = "native"
13-
const APP_CPU_TARGET = "generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"
13+
# See https://github.com/JuliaCI/julia-buildbot/blob/489ad6dee5f1e8f2ad341397dc15bb4fce436b26/master/inventory.py
14+
function default_app_cpu_target()
15+
if Sys.ARCH === :i686
16+
return "pentium4;sandybridge,-xsaveopt,clone_all"
17+
elseif Sys.ARCH === :x86_64
18+
return "generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"
19+
elseif Sys.ARCH === :arm
20+
return "armv7-a;armv7-a,neon;armv7-a,neon,vfp4"
21+
elseif Sys.ARCH === :aarch64
22+
return "generic" # is this really the best here?
23+
elseif Sys.ARCH === :powerpc64le
24+
return "pwr8"
25+
else
26+
return "generic"
27+
end
28+
end
1429

1530
current_process_sysimage_path() = unsafe_string(Base.JLOptions().image_file)
1631

@@ -19,18 +34,28 @@ all_stdlibs() = readdir(Sys.STDLIB)
1934
yesno(b::Bool) = b ? "yes" : "no"
2035

2136
function bitflag()
22-
if Sys.ARCH == :aarch64 || Sys.ARCH == :arm
23-
return ``
37+
if Sys.ARCH == :i686
38+
return `-m32`
39+
elseif Sys.ARCH == :x86_64
40+
return `-m64`
2441
else
25-
return Int == Int32 ? `-m32` : `-m64`
42+
return ``
2643
end
2744
end
2845

2946
function march()
30-
if Sys.ARCH == :aarch64 || Sys.ARCH == :arm
31-
return (Int == Int32 ? `-march=armv7-a` : `-march=armv8-a+crypto+simd`)
47+
if Sys.ARCH === :i686
48+
return "-march=pentium4"
49+
elseif Sys.ARCH === :x86_64
50+
return "-march=x86-64"
51+
elseif Sys.ARCH === :arm
52+
return "-march=armv7-a+simd"
53+
elseif Sys.ARCH === :aarch64
54+
return "-march=armv8-a+crypto+simd"
55+
elseif Sys.ARCH === :powerpc64le
56+
return nothing
3257
else
33-
return (Int == Int32 ? `-march=pentium4` : ``)
58+
return nothing
3459
end
3560
end
3661

@@ -408,7 +433,8 @@ function create_sysimg_from_object_file(input_object::String, sysimage_path::Str
408433
end
409434
extra = Sys.iswindows() ? `-Wl,--export-all-symbols` : ``
410435
compiler = get_compiler()
411-
cmd = `$compiler $(bitflag()) $(march()) -shared -L$(julia_libdir) -o $sysimage_path $o_file -ljulia $extra`
436+
m = something(march(), ``)
437+
cmd = `$compiler $(bitflag()) $m -shared -L$(julia_libdir) -o $sysimage_path $o_file -ljulia $extra`
412438
@debug "running $cmd"
413439
windows_compiler_artifact_path(compiler) do
414440
run(cmd)
@@ -531,7 +557,7 @@ function create_app(package_dir::String,
531557
filter_stdlibs=false,
532558
audit=true,
533559
force=false,
534-
cpu_target::String=APP_CPU_TARGET)
560+
cpu_target::String=default_app_cpu_target())
535561
precompile_statements_file = abspath.(precompile_statements_file)
536562
package_dir = abspath(package_dir)
537563
ctx = create_pkg_context(package_dir)
@@ -610,7 +636,8 @@ function create_executable_from_sysimg(;sysimage_path::String,
610636
rpath = `-Wl,-rpath,\$ORIGIN:\$ORIGIN/../lib`
611637
end
612638
compiler = get_compiler()
613-
cmd = `$compiler -DJULIAC_PROGRAM_LIBNAME=$(repr(sysimage_path)) $(bitflag()) $(march()) -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $rpath $flags`
639+
m = something(march(), ``)
640+
cmd = `$compiler -DJULIAC_PROGRAM_LIBNAME=$(repr(sysimage_path)) $(bitflag()) $m -o $(executable_path) $(wrapper) $(sysimage_path) -O2 $rpath $flags`
614641
@debug "running $cmd"
615642
run(cmd)
616643
windows_compiler_artifact_path(compiler) do

test/runtests.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ cp(joinpath(DEPOT_PATH[1], "registries", "General"), joinpath(new_depot, "regist
1111
ENV["JULIA_DEPOT_PATH"] = new_depot
1212
Base.init_depot_path()
1313

14+
is_slow_ci = haskey(ENV, "CI") && Sys.ARCH == :aarch64
15+
16+
if haskey(ENV, "CI")
17+
@show Sys.ARCH
18+
end
19+
1420
@testset "PackageCompiler.jl" begin
1521
tmp = mktempdir()
1622
sysimage_path = joinpath(tmp, "sys." * Libdl.dlext)
@@ -31,9 +37,9 @@ Base.init_depot_path()
3137
# TODO: Also test something that actually gives audit warnings
3238
@test_logs PackageCompiler.audit_app(app_source_dir)
3339
app_compiled_dir = joinpath(tmp, "MyAppCompiled")
34-
for incremental in (true, false)
40+
for incremental in (is_slow_ci ? (false,) : (true, false))
3541
if incremental == false
36-
filter_stdlibs = (true, false)
42+
filter_stdlibs = (is_slow_ci ? (true, ) : (true, false))
3743
else
3844
filter_stdlibs = (false,)
3945
end

0 commit comments

Comments
 (0)