-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adaption to Windows #151
Merged
Merged
adaption to Windows #151
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e3fe600
adaption to windows: use clang to generate executable, skip GPUCompiler
Thomas008 30a90c4
sinple test
Thomas008 bb19993
bug fix in if-then-else
Thomas008 116e8b5
try optimisation
Thomas008 9b12daa
without optimisation
Thomas008 ce33e29
rewrite a comment
Thomas008 204d1b4
data structures and control flow tests
Thomas008 6f59c00
Compile in current directory rather than hard-coded path
brenhinkeller a150c50
Merge branch 'master' into master
brenhinkeller 7366189
`native_llvm_module` has been renamed to `static_llvm_module`
brenhinkeller e40370f
Clarify choice of clang
brenhinkeller a9c2ffe
Test new llvm-to-clang compilation pipeline
brenhinkeller 81534ef
Attempt to get tests passing
brenhinkeller f8a69b2
fix passthrough of kwargs
brenhinkeller a56708a
Special case for apple as well
brenhinkeller 88ec2a3
Delete test/simple_test.jl (replaced by tests in testcore.jl)
brenhinkeller bac5bbb
Delete test/stc_test.jl (since not used in testsystem -- use locally …
brenhinkeller 158c2ea
More consistent naming of `emit_llvm_only` option
brenhinkeller c534d71
Bump version to 0.7.1
brenhinkeller 39e385d
Do we dare attempt windows CI?
brenhinkeller 4f0c29e
Nope not yet!
brenhinkeller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,13 +98,13 @@ shell> ./hello | |
Hello, world! | ||
``` | ||
""" | ||
function compile_executable(f::Function, types=(), path::String="./", name=fix_name(f); | ||
function compile_executable(f::Function, types=(), path::String=pwd(), name=fix_name(f); | ||
also_expose=Tuple{Function, Tuple{DataType}}[], target::StaticTarget=StaticTarget(), | ||
kwargs...) | ||
compile_executable(vcat([(f, types)], also_expose), path, name; target, kwargs...) | ||
end | ||
|
||
function compile_executable(funcs::Union{Array,Tuple}, path::String="./", name=fix_name(first(first(funcs))); | ||
function compile_executable(funcs::Union{Array,Tuple}, path::String=pwd(), name=fix_name(first(first(funcs))); | ||
filename = name, | ||
demangle = true, | ||
cflags = ``, | ||
|
@@ -128,14 +128,14 @@ end | |
|
||
""" | ||
```julia | ||
compile_shlib(f::Function, types::Tuple, [path::String="./"], [name::String=string(nameof(f))]; | ||
compile_shlib(f::Function, types::Tuple, [path::String=pwd()], [name::String=string(nameof(f))]; | ||
filename::String=name, | ||
cflags=``, | ||
method_table=StaticCompiler.method_table, | ||
target::StaticTarget=StaticTarget(), | ||
kwargs...) | ||
|
||
compile_shlib(funcs::Array, [path::String="./"]; | ||
compile_shlib(funcs::Array, [path::String=pwd()]; | ||
filename="libfoo", | ||
demangle=true, | ||
cflags=``, | ||
|
@@ -172,15 +172,15 @@ julia> ccall(("test", "test.dylib"), Float64, (Int64,), 100_000) | |
5.2564961094956075 | ||
``` | ||
""" | ||
function compile_shlib(f::Function, types=(), path::String="./", name=fix_name(f); | ||
function compile_shlib(f::Function, types=(), path::String=pwd(), name=fix_name(f); | ||
filename=name, | ||
target::StaticTarget=StaticTarget(), | ||
kwargs... | ||
) | ||
compile_shlib(((f, types),), path; filename, target, kwargs...) | ||
end | ||
# As above, but taking an array of functions and returning a single shlib | ||
function compile_shlib(funcs::Union{Array,Tuple}, path::String="./"; | ||
function compile_shlib(funcs::Union{Array,Tuple}, path::String=pwd(); | ||
filename = "libfoo", | ||
demangle = true, | ||
cflags = ``, | ||
|
@@ -289,10 +289,11 @@ function generate_executable(funcs::Union{Array,Tuple}, path=tempname(), name=fi | |
demangle = true, | ||
cflags = ``, | ||
target::StaticTarget=StaticTarget(), | ||
llvm_to_clang = Sys.iswindows(), | ||
kwargs... | ||
) | ||
exec_path = joinpath(path, filename) | ||
_, obj_path = generate_obj(funcs, path, filename; demangle, target, kwargs...) | ||
_, obj_or_ir_path = generate_obj(funcs, path, filename; emit_llvm_only=llvm_to_clang, demangle, target, kwargs...) | ||
# Pick a compiler | ||
if !isnothing(target.compiler) | ||
cc = `$(target.compiler)` | ||
|
@@ -301,10 +302,10 @@ function generate_executable(funcs::Union{Array,Tuple}, path=tempname(), name=fi | |
end | ||
|
||
# Compile! | ||
if Sys.isapple() | ||
if Sys.isapple() && !llvm_to_clang | ||
# Apple no longer uses _start, so we can just specify a custom entry | ||
entry = demangle ? "_$name" : "_julia_$name" | ||
run(`$cc -e $entry $cflags $obj_path -o $exec_path`) | ||
run(`$cc -e $entry $cflags $obj_or_ir_path -o $exec_path`) | ||
else | ||
fn = demangle ? "$name" : "julia_$name" | ||
# Write a minimal wrapper to avoid having to specify a custom entry | ||
|
@@ -319,9 +320,19 @@ function generate_executable(funcs::Union{Array,Tuple}, path=tempname(), name=fi | |
return 0; | ||
}""") | ||
close(f) | ||
run(`$cc $wrapper_path $cflags $obj_path -o $exec_path`) | ||
if llvm_to_clang # (required on Windows) | ||
# Use clang (llc) to generate an executable from the LLVM IR | ||
if Sys.iswindows() | ||
run(`cmd \c clang -Wno-override-module $wrapper_path $obj_or_ir_path -o $exec_path`) | ||
else | ||
run(`$(clang()) -Wno-override-module $wrapper_path $obj_or_ir_path -o $exec_path`) | ||
end | ||
else | ||
run(`$cc $wrapper_path $cflags $obj_or_ir_path -o $exec_path`) | ||
end | ||
|
||
# Clean up | ||
run(`rm $wrapper_path`) | ||
rm(wrapper_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (Julia's built-in |
||
end | ||
path, name | ||
end | ||
|
@@ -539,20 +550,30 @@ function generate_obj(funcs::Union{Array,Tuple}, path::String = tempname(), file | |
strip_asm = true, | ||
opt_level = 3, | ||
target::StaticTarget=StaticTarget(), | ||
emit_llvm_only = Sys.iswindows(), | ||
kwargs...) | ||
f, tt = funcs[1] | ||
mkpath(path) | ||
obj_path = joinpath(path, "$filenamebase.o") | ||
mod = static_llvm_module(funcs; demangle, kwargs...) | ||
obj = GPUCompiler.JuliaContext() do ctx | ||
fakejob, _ = static_job(f, tt; target, kwargs...) | ||
obj, _ = GPUCompiler.emit_asm(fakejob, mod; strip=strip_asm, validate=false, format=LLVM.API.LLVMObjectFile) | ||
obj | ||
end | ||
open(obj_path, "w") do io | ||
write(io, obj) | ||
|
||
if emit_llvm_only # (Required on Windows) | ||
ir_path = joinpath(path, "$filenamebase.ll") | ||
open(ir_path, "w") do io | ||
write(io, string(mod)) | ||
end | ||
return path, ir_path | ||
else | ||
obj_path = joinpath(path, "$filenamebase.o") | ||
obj = GPUCompiler.JuliaContext() do ctx | ||
fakejob, _ = static_job(f, tt; target, kwargs...) | ||
obj, _ = GPUCompiler.emit_asm(fakejob, mod; strip=strip_asm, validate=false, format=LLVM.API.LLVMObjectFile) | ||
obj | ||
end | ||
open(obj_path, "w") do io | ||
write(io, obj) | ||
end | ||
return path, obj_path | ||
end | ||
path, obj_path | ||
end | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using StaticCompiler | ||
using StaticTools | ||
|
||
hello() = println(c"Hello world!") | ||
hello() | ||
|
||
# Attempt to compile | ||
compile_executable(hello, (), pwd()) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to
pwd()
which should be system-agnostic, whereas"./"
was unix-only