class Xgboost < Formula desc "Scalable, Portable and Distributed Gradient Boosting Library" homepage "https://xgboost.ai/" url "https://github.com/dmlc/xgboost/releases/download/v3.2.0/xgboost-src-3.2.0.tar.gz" sha256 "16a31dfbc0c54544c9c36ab5f696fa7b646c125f161c52c814d757a58241a404" license "Apache-2.0" livecheck do url :stable strategy :github_latest end bottle do sha256 cellar: :any, arm64_tahoe: "5a95ce8b876749dcc5ef5675674500ead83b3da69b64945455f20cc6765c8365" sha256 cellar: :any, arm64_sequoia: "e346db9ed7ee1b5a718b0ee94ae7c311aa1baa31b7c0ed01db4ad93ae600d84b" sha256 cellar: :any, arm64_sonoma: "349ede65433762b092f684a0130fe9b63c134d8417e73cad766dd03cb35e9b5a" sha256 cellar: :any, sonoma: "bae04c0461e2a5e996e67a9e0c2e2648b7e58fa8cf9e9a35065ef1c8daa2b6cb" sha256 cellar: :any_skip_relocation, arm64_linux: "5969e0b1577357773b3cf5daca4a7237fa62dae7dc3ce95c54dcae44944dd8f0" sha256 cellar: :any_skip_relocation, x86_64_linux: "bbd350d38e5d16cc7f46993d316bdee723c7a4e7b9a53dab9e2d0912e5678e4f" end depends_on "cmake" => :build on_macos do depends_on "llvm" => :build if DevelopmentTools.clang_build_version <= 1100 depends_on "libomp" end fails_with :clang do build 1100 cause <<~EOS clang: error: unable to execute command: Segmentation fault: 11 clang: error: clang frontend command failed due to signal (use -v to see invocation) make[2]: *** [src/CMakeFiles/objxgboost.dir/tree/updater_quantile_hist.cc.o] Error 254 EOS end def install system "cmake", "-S", ".", "-B", "build", *std_cmake_args system "cmake", "--build", "build" system "cmake", "--install", "build" pkgshare.install "demo" end test do cp_r (pkgshare/"demo"), testpath (testpath/"test.cpp").write <<~CPP #include #include int main() { std::string train_data = "#{testpath}/demo/data/agaricus.txt.train?format=libsvm"; DMatrixHandle dtrain; if (XGDMatrixCreateFromFile(train_data.c_str(), 0, &dtrain) != 0) { std::cerr << "Failed to load training data: " << train_data << std::endl; std::cerr << "Last error message: " << XGBGetLastError() << std::endl; return 1; } // Create booster and set parameters BoosterHandle booster; if (XGBoosterCreate(&dtrain, 1, &booster) != 0) { std::cerr << "Failed to create booster" << std::endl; return 1; } if (XGBoosterSetParam(booster, "max_depth", "2") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } if (XGBoosterSetParam(booster, "eta", "1") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } if (XGBoosterSetParam(booster, "objective", "binary:logistic") != 0) { std::cerr << "Failed to set parameter" << std::endl; return 1; } // Train the model for (int iter = 0; iter < 10; ++iter) { if (XGBoosterUpdateOneIter(booster, iter, dtrain) != 0) { std::cerr << "Failed to update booster" << std::endl; return 1; } } // Free resources XGBoosterFree(booster); XGDMatrixFree(dtrain); std::cout << "Test completed successfully" << std::endl; return 0; } CPP system ENV.cxx, "test.cpp", "-I#{include}", "-L#{lib}", "-lxgboost", "-o", "test" system "./test" end end