-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require "yaml" | ||
|
||
module ::Utils | ||
def self.add_clang_version_to_conan_settings(version) | ||
system "conan", "config", "init" | ||
conan_home = safe_popen_read("conan", "config", "home").strip | ||
settings_file = "#{conan_home}/settings.yml" | ||
settings = YAML.load_file(settings_file, aliases: true) | ||
clang_versions = settings["compiler"]["clang"]["version"] | ||
unless clang_versions.include?(version) | ||
clang_versions << version | ||
File.write(settings_file, YAML.dump(settings)) | ||
end | ||
end | ||
end | ||
|
||
class CatboostModelCpp < Formula | ||
desc "Gradient Boosting on Decision Trees C++ Model Library" | ||
homepage "https://catboost.ai" | ||
url "https://github.com/catboost/catboost.git", | ||
tag: "v1.2.7", | ||
revision: "f903943a8cd903a117c3d3c8421cc72d3910562c" | ||
license "Apache-2.0" | ||
head "https://github.com/catboost/catboost.git", branch: "master" | ||
|
||
depends_on "cmake" => :build | ||
depends_on "conan@1" => :build | ||
depends_on "ninja" => :build | ||
|
||
uses_from_macos "llvm" => :build | ||
|
||
def install | ||
Check failure on line 32 in Formula/catboost-model-cpp.rb GitHub Actions / test-bot (ubuntu-latest)`brew install --verbose --formula --build-bottle cdalvaro/tap/catboost-model-cpp` failed on Linux!
|
||
Utils.add_clang_version_to_conan_settings(Formula["llvm"].version.major.to_s) if ENV.key?("GITHUB_ACTIONS") | ||
|
||
args = [ | ||
"-DCATBOOST_COMPONENTS=libs", | ||
"-DHAVE_CUDA=NO", | ||
"-DCMAKE_POSITION_INDEPENDENT_CODE=On", | ||
"-DCMAKE_TOOLCHAIN_FILE=#{buildpath}/build/toolchains/clang.toolchain", | ||
] | ||
|
||
cmakepath = buildpath/"cmake-build" | ||
system "cmake", "-S", ".", "-B", cmakepath, "-G", "Ninja", *args, *std_cmake_args | ||
system "ninja", "-C", cmakepath, "catboostmodel" | ||
|
||
lib.install cmakepath/"catboost/libs/model_interface/libcatboostmodel.dylib" | ||
%w[c_api.h wrapped_calcer.h].each do |header| | ||
(include/"catboost/model_interface").install Dir[buildpath/"catboost/libs/model_interface/#{header}"] | ||
end | ||
end | ||
|
||
test do | ||
(testpath/"test.cpp").write <<~EOS | ||
#include <catboost/model_interface/wrapped_calcer.h> | ||
#include <iostream> | ||
int main(int argc, char** argv) { | ||
{ | ||
ModelCalcerWrapper calcer; | ||
calcer.init_from_file("model.bin"); | ||
std::cout << calcer.CalcFlat(std::vector<float>(100)) << std::endl; | ||
std::cout << calcer.CalcFlat(std::vector<float>(100, 1.0f)) << std::endl; | ||
} | ||
{ | ||
ModelCalcerWrapper calcer("model.bin"); | ||
std::vector<std::string> catFeatures = {"1", "2", "3"}; | ||
std::cout << calcer.Calc(std::vector<float>(100), catFeatures) << std::endl; | ||
std::cout << calcer.Calc(std::vector<float>(100, 1.0f), std::vector<std::string>()) << std::endl; | ||
} | ||
return 0; | ||
} | ||
EOS | ||
system ENV.cxx, "test.cpp", "-std=c++1y", "-L#{lib}", "-o", "test" | ||
system "./test" | ||
end | ||
end |