class Xgboost < Formula desc "Scalable, Portable and Distributed Gradient Boosting Library" homepage "https://xgboost.ai/" url "https://github.com/dmlc/xgboost/releases/download/v3.1.3/xgboost-src-3.1.3.tar.gz" sha256 "67800a7c1c0455c22c9be73dbf3c39bfd9ac9627b2cb617eb2795fd675a9d49e" license "Apache-2.0" livecheck do url :stable strategy :github_latest end bottle do sha256 cellar: :any, arm64_tahoe: "183890261aed9bb97ad5ee316564664e16b36215bb70a3a91e63d489f4ebf537" sha256 cellar: :any, arm64_sequoia: "3563bf70ceffc413bfd1671c34d1893b787b576ebac53ba4415a666601ecb290" sha256 cellar: :any, arm64_sonoma: "8f01af1809d93dde95bfff54e79f6671e60db222b74b1a09a8092ed2805303fd" sha256 cellar: :any, sonoma: "27bf55b74bc1ae7c8f54476ea95452ae53c390f4a135a4c87a48d074ed81ab88" sha256 cellar: :any_skip_relocation, arm64_linux: "527fcabfb6aa2663a47ef5195fe5c3eba4770571ccb15a583c9f4f4a6cdadfd7" sha256 cellar: :any_skip_relocation, x86_64_linux: "580be1b22fdc397a3e8474ac1b1a2d83b3eb763803063ee1859aad076fce343f" 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