-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from JuliaLabs/vc/artifact
CMake support for mlir-jl-tblgen
- Loading branch information
Showing
6 changed files
with
132 additions
and
5 deletions.
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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[deps] | ||
LLVM_full_jll = "a3ccf953-465e-511d-b87f-60a6490c289d" | ||
|
||
[compat] | ||
LLVM_full_jll = "15" | ||
CMake_jll = "3f4e10e2-61f2-5801-8945-23b9d642d0e6" | ||
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | ||
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | ||
Preferences = "21216c6a-2e73-6563-6e65-726566657250" | ||
Scratch = "6c6a2e73-6563-6170-7368-637461726353" |
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,74 @@ | ||
# build a local version of mlir-jl-tblgen | ||
|
||
using Pkg | ||
Pkg.activate(@__DIR__) | ||
Pkg.instantiate() | ||
|
||
if haskey(ENV, "GITHUB_ACTIONS") | ||
println("::warning ::Using a locally-built mlir-jl-tblgen; A bump of mlir_jl_tblgen_jll will be required before releasing MLIR.jl.") | ||
end | ||
|
||
using Pkg, Scratch, Preferences, Libdl, CMake_jll | ||
|
||
MLIR = Base.UUID("bfde9dd4-8f40-4a1e-be09-1475335e1c92") | ||
|
||
# get scratch directories | ||
scratch_dir = get_scratch!(MLIR, "build") | ||
isdir(scratch_dir) && rm(scratch_dir; recursive=true) | ||
source_dir = joinpath(@__DIR__, "tblgen") | ||
|
||
# get build directory | ||
build_dir = if isempty(ARGS) | ||
mktempdir() | ||
else | ||
ARGS[1] | ||
end | ||
mkpath(build_dir) | ||
|
||
# download LLVM | ||
Pkg.activate(; temp=true) | ||
llvm_assertions = try | ||
cglobal((:_ZN4llvm24DisableABIBreakingChecksE, Base.libllvm_path()), Cvoid) | ||
false | ||
catch | ||
true | ||
end | ||
llvm_pkg_version = "$(Base.libllvm_version.major).$(Base.libllvm_version.minor)" | ||
LLVM = if llvm_assertions | ||
Pkg.add(name="LLVM_full_assert_jll", version=llvm_pkg_version) | ||
using LLVM_full_assert_jll | ||
LLVM_full_assert_jll | ||
else | ||
Pkg.add(name="LLVM_full_jll", version=llvm_pkg_version) | ||
using LLVM_full_jll | ||
LLVM_full_jll | ||
end | ||
LLVM_DIR = joinpath(LLVM.artifact_dir, "lib", "cmake", "llvm") | ||
MLIR_DIR = joinpath(LLVM.artifact_dir, "lib", "cmake", "mlir") | ||
|
||
# build and install | ||
@info "Building" source_dir scratch_dir build_dir LLVM_DIR MLIR_DIR | ||
cmake() do cmake_path | ||
config_opts = `-DLLVM_ROOT=$(LLVM_DIR) -DMLIR_ROOT=$(MLIR_DIR) -DCMAKE_INSTALL_PREFIX=$(scratch_dir)` | ||
if Sys.iswindows() | ||
# prevent picking up MSVC | ||
config_opts = `$config_opts -G "MSYS Makefiles"` | ||
end | ||
run(`$cmake_path $config_opts -B$(build_dir) -S$(source_dir)`) | ||
run(`$cmake_path --build $(build_dir) --target install`) | ||
end | ||
|
||
# discover built binaries | ||
built_libs = filter(readdir(joinpath(scratch_dir, "lib"))) do file | ||
endswith(file, ".$(Libdl.dlext)") | ||
end | ||
lib_path = joinpath(scratch_dir, "lib", only(built_libs)) | ||
isfile(lib_path) || error("Could not find library $lib_path in build directory") | ||
|
||
# tell LLVM.jl to load our library instead of the default artifact one | ||
set_preferences!( | ||
joinpath(dirname(@__DIR__), "LocalPreferences.toml"), | ||
"mlir_jl_tblgen_jll", | ||
"mlir_jl_tblgen" => lib_path; | ||
force=true, | ||
) |
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,46 @@ | ||
|
||
cmake_minimum_required(VERSION 3.3) | ||
|
||
SET(CMAKE_CXX_FLAGS "-Wall -fPIC -fno-rtti") | ||
cmake_policy(SET CMP0074 NEW) | ||
cmake_policy(SET CMP0077 NEW) | ||
|
||
project(mlir-jl-tblgen | ||
LANGUAGES | ||
CXX | ||
C | ||
) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
|
||
find_package(LLVM REQUIRED CONFIG) | ||
find_package(MLIR REQUIRED CONFIG) | ||
set(CMAKE_MODULE_PATH | ||
${CMAKE_MODULE_PATH} | ||
${LLVM_CMAKE_DIR} | ||
${MLIR_CMAKE_DIR} | ||
) | ||
include(AddLLVM) | ||
include(HandleLLVMOptions) | ||
include(AddMLIR) | ||
|
||
message(STATUS "Found LLVM: ${LLVM_VERSION}") | ||
message(STATUS "Found MLIR: ${MLIR_VERSION}") | ||
|
||
add_definitions(${LLVM_DEFINITIONS}) | ||
add_definitions(${MLIR_DEFINITIONS}) | ||
include_directories(${LLVM_INCLUDE_DIRS}) | ||
include_directories(${MLIR_INCLUDE_DIRS}) | ||
|
||
add_executable(mlir-jl-tblgen | ||
mlir-jl-tblgen.cc | ||
jl-generators.cc) | ||
|
||
target_link_libraries(mlir-jl-tblgen PUBLIC | ||
MLIRTableGen | ||
LLVMTableGen | ||
) | ||
|
||
install(TARGETS mlir-jl-tblgen DESTINATION bin) |
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module MLIR | ||
|
||
import LLVM | ||
import mlir_jl_tblgen_jll | ||
|
||
module API | ||
using CEnum | ||
|