Skip to content

Commit

Permalink
Merge pull request #82 from brenhinkeller/master
Browse files Browse the repository at this point in the history
Add `cflags` kwarg to `compile_executable` and friends
  • Loading branch information
brenhinkeller authored Jul 19, 2022
2 parents e79b6a6 + ca99263 commit d33e25c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 464 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
name: TagBot
on:
schedule:
- cron: 0 * * * *
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
2 changes: 1 addition & 1 deletion .github/workflows/ci-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '~1.8.0-0'
- '1.8.0-rc1'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
version:
- '1.7'
- '~1.8.0-0'
- '1.8.0-rc1'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaticCompiler"
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
authors = ["Tom Short"]
version = "0.4.4"
version = "0.4.5"

[deps]
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
Expand Down
45 changes: 30 additions & 15 deletions src/StaticCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ Hello, world!
```
"""
function compile_executable(f, types=(), path::String="./", name=GPUCompiler.safe_name(repr(f));
filename=name,
kwargs...)
filename=name,
cflags=``,
kwargs...
)

tt = Base.to_tuple_type(types)
# tt == Tuple{} || tt == Tuple{Int, Ptr{Ptr{UInt8}}} || error("input type signature $types must be either () or (Int, Ptr{Ptr{UInt8}})")
Expand All @@ -239,7 +241,7 @@ function compile_executable(f, types=(), path::String="./", name=GPUCompiler.saf
# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this

generate_executable(f, tt, path, name, filename; kwargs...)
generate_executable(f, tt, path, name, filename; cflags=cflags, kwargs...)

joinpath(abspath(path), filename)
end
Expand All @@ -252,8 +254,10 @@ compile_shlib(f, types::Tuple, path::String, name::String=repr(f); filename::Str
As `compile_executable`, but compiling to a standalone `.dylib`/`.so` shared library.
"""
function compile_shlib(f, types=(), path::String="./", name=GPUCompiler.safe_name(repr(f));
filename=name,
kwargs...)
filename=name,
cflags=``,
kwargs...
)

tt = Base.to_tuple_type(types)
isconcretetype(tt) || error("input type signature $types is not concrete")
Expand All @@ -263,8 +267,7 @@ function compile_shlib(f, types=(), path::String="./", name=GPUCompiler.safe_nam

# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this

generate_shlib(f, tt, path, name, filename; kwargs...)
generate_shlib(f, tt, path, name, filename; cflags=cflags, kwargs...)

joinpath(abspath(path), filename * "." * Libdl.dlext)
end
Expand Down Expand Up @@ -348,7 +351,10 @@ test (generic function with 1 method)
julia> path, name = StaticCompiler.generate_executable(test, Tuple{Int64}, "./scratch")
```
"""
function generate_executable(f, tt, path::String = tempname(), name = GPUCompiler.safe_name(repr(f)), filename::String=string(name); kwargs...)
function generate_executable(f, tt, path=tempname(), name=GPUCompiler.safe_name(repr(f)), filename=string(name);
cflags=``,
kwargs...
)
mkpath(path)
obj_path = joinpath(path, "$filename.o")
exec_path = joinpath(path, filename)
Expand All @@ -366,7 +372,7 @@ function generate_executable(f, tt, path::String = tempname(), name = GPUCompile
if Sys.isapple()
# Apple no longer uses _start, so we can just specify a custom entry
entry = "_julia_$name"
run(`$cc -e $entry $obj_path -o $exec_path`)
run(`$cc -e $entry $cflags $obj_path -o $exec_path`)
else
# Write a minimal wrapper to avoid having to specify a custom entry
wrapper_path = joinpath(path, "wrapper.c")
Expand All @@ -377,7 +383,7 @@ function generate_executable(f, tt, path::String = tempname(), name = GPUCompile
return 0;
}""")
close(f)
run(`$cc $wrapper_path $obj_path -o $exec_path`)
run(`$cc $wrapper_path $cflags $obj_path -o $exec_path`)
# Clean up
run(`rm $wrapper_path`)
end
Expand Down Expand Up @@ -416,7 +422,11 @@ julia> ccall(StaticCompiler.generate_shlib_fptr(path, name), Float64, (Int64,),
5.256496109495593
```
"""
function generate_shlib(f, tt, path::String = tempname(), name = GPUCompiler.safe_name(repr(f)), filename::String=name; kwargs...)
function generate_shlib(f, tt, path=tempname(), name=GPUCompiler.safe_name(repr(f)), filename=name;
cflags=``,
kwargs...
)

mkpath(path)
obj_path = joinpath(path, "$filename.o")
lib_path = joinpath(path, "$filename.$(Libdl.dlext)")
Expand All @@ -430,7 +440,7 @@ function generate_shlib(f, tt, path::String = tempname(), name = GPUCompiler.saf
# Pick a Clang
cc = Sys.isapple() ? `cc` : clang()
# Compile!
run(`$cc -shared -o $lib_path $obj_path`)
run(`$cc -shared $cflags $obj_path -o $lib_path`)

path, name
end
Expand Down Expand Up @@ -503,22 +513,27 @@ function generate_obj(funcs::Array, path::String = tempname(), filenamebase::Str
path, obj_path
end

function generate_shlib(funcs::Array, path::String = tempname(), filename::String="libfoo"; demangle=false, kwargs...)
function generate_shlib(funcs::Array, path::String = tempname(), filename::String="libfoo";
demangle=false,
cflags=``,
kwargs...
)

lib_path = joinpath(path, "$filename.$(Libdl.dlext)")

_,obj_path = generate_obj(funcs, path, filename; demangle=demangle, kwargs...)
# Pick a Clang
cc = Sys.isapple() ? `cc` : clang()
# Compile!
run(`$cc -shared -o $lib_path $obj_path`)
run(`$cc -shared $cflags $obj_path -o $lib_path `)

path, name
end

function compile_shlib(funcs::Array, path::String="./";
filename="libfoo",
demangle=false,
cflags=``,
kwargs...)
for func in funcs
f, types = func
Expand All @@ -532,7 +547,7 @@ function compile_shlib(funcs::Array, path::String="./";
# Would be nice to use a compiler pass or something to check if there are any heap allocations or references to globals
# Keep an eye on https://github.com/JuliaLang/julia/pull/43747 for this

generate_shlib(funcs, path, filename; demangle=demangle, kwargs...)
generate_shlib(funcs, path, filename; demangle=demangle, cflags=cflags, kwargs...)

joinpath(abspath(path), filename * "." * Libdl.dlext)
end
Expand Down
Loading

2 comments on commit d33e25c

@brenhinkeller
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • Add cflags keyword argument to compile_executable/compile_shlib (and to the underlying generate_executable/generate_shlib), allowing you to, e.g., specify libraries to link against at compile time

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/64506

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.5 -m "<description of version>" d33e25ca76fa7857e53d7315f2f285d65468a2bc
git push origin v0.4.5

Please sign in to comment.