Skip to content
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

remove makefile dependency #27

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion shard.yml
Expand Up @@ -5,7 +5,7 @@ authors:
- Konstantin Makarchev <kostya27@gmail.com>

scripts:
postinstall: cd src/ext && make package
postinstall: crystal run src/ext/build_lexbor.cr

crystal: ">= 0.35.1, < 2.0.0"
license: MIT
48 changes: 48 additions & 0 deletions src/ext/build_lexbor.cr
@@ -0,0 +1,48 @@
REV = "b0dc514cf81bb830aa1db4e273739436dd6597c9"

def static_link_thread_windows(args : Array(String))
args << "-DCMAKE_POLICY_DEFAULT_CMP0091=NEW"
args << "-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded"
end

def print_stdout_stderr(proc : Process)
while (line = proc.output.gets) || (line = proc.error.gets)
puts line
end
end

current_path = Path[__FILE__]
lexbor_c_path = (current_path.parent) / "lexbor-c"
args = ["clone", "https://github.com/lexbor/lexbor.git", lexbor_c_path.to_s]

unless File.directory? lexbor_c_path
# TODO: Check if the git clone fails.
Process.run("git", args: args) { |p| print_stdout_stderr(p) }
end

# Checkout to the specific SHA
Process.run("git", args: ["reset", "--hard", REV], chdir: lexbor_c_path.to_s) { |p| print_stdout_stderr(p) }

# Make the build directory
lexbor_build_path = lexbor_c_path / "build"
unless File.directory? lexbor_build_path
Dir.mkdir(lexbor_build_path)
end

cmake_args = [
"..",
"-DCMAKE_BUILD_TYPE=Release",
"-DLEXBOR_BUILD_TESTS_CPP=OFF",
"-DLEXBOR_INSTALL_HEADERS=OFF",
"-DLEXBOR_BUILD_SHARED=OFF",
]

{% if flag?(:win32) %}
static_link_thread_windows(cmake_args)
{% end %}

Process.run("cmake", args: cmake_args, chdir: lexbor_build_path.to_s) { |p| print_stdout_stderr(p) }

# Build the library

Process.run("cmake", args: ["--build", ".", "--config", "Release", "-j", System.cpu_count.to_s], chdir: lexbor_build_path.to_s) { |p| print_stdout_stderr(p) }
4 changes: 4 additions & 0 deletions src/lexbor/lib.cr
@@ -1,7 +1,11 @@
require "./lib/constants"

module Lexbor
{% if flag?(:win32) %}
@[Link(ldflags: "#{__DIR__}/../ext/lexbor-c/build/Release/lexbor_static.lib")]
{% else %}
@[Link(ldflags: "#{__DIR__}/../ext/lexbor-c/build/liblexbor_static.a")]
{% end %}
lib Lib
type DocT = Void*
type CollectionT = Void*
Expand Down