From 3cee1a9e20e4902e22ddd85753d20198884ec703 Mon Sep 17 00:00:00 2001 From: "Addisu Z. Taddese" Date: Fri, 17 Jan 2025 19:00:08 +0100 Subject: [PATCH] gz-sim10: new formula in jetty (#2940) Signed-off-by: Addisu Z. Taddese Co-authored-by: Steve Peters --- Aliases/gz-sim10 | 1 - Formula/gz-sim10.rb | 162 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 1 deletion(-) delete mode 120000 Aliases/gz-sim10 create mode 100644 Formula/gz-sim10.rb diff --git a/Aliases/gz-sim10 b/Aliases/gz-sim10 deleted file mode 120000 index a08f8a57b..000000000 --- a/Aliases/gz-sim10 +++ /dev/null @@ -1 +0,0 @@ -../Formula/gz-sim9.rb \ No newline at end of file diff --git a/Formula/gz-sim10.rb b/Formula/gz-sim10.rb new file mode 100644 index 000000000..b4718a6de --- /dev/null +++ b/Formula/gz-sim10.rb @@ -0,0 +1,162 @@ +class GzSim10 < Formula + desc "Gazebo Sim robot simulator" + homepage "https://github.com/gazebosim/gz-sim" + url "https://github.com/gazebosim/gz-sim.git", branch: "main" + version "9.999.999-0-20250117" + license "Apache-2.0" + + head "https://github.com/gazebosim/gz-sim.git", branch: "gz-sim10" + + depends_on "cmake" => :build + depends_on "pybind11" => :build + depends_on "python@3.13" => [:build, :test] + depends_on "abseil" + depends_on "ffmpeg" + depends_on "gflags" + depends_on "google-benchmark" + depends_on "gz-cmake4" + depends_on "gz-common6" + depends_on "gz-fuel-tools10" + depends_on "gz-gui10" + depends_on "gz-math8" + depends_on "gz-msgs11" + depends_on "gz-physics8" + depends_on "gz-plugin3" + depends_on "gz-rendering9" + depends_on "gz-sensors9" + depends_on "gz-tools2" + depends_on "gz-transport14" + depends_on "gz-utils3" + depends_on macos: :mojave # c++17 + depends_on "pkgconf" + depends_on "protobuf" + depends_on "qt@5" + depends_on "ruby" + depends_on "sdformat15" + depends_on "tinyxml2" + + def pythons + deps.map(&:to_formula) + .select { |f| f.name.match?(/^python@3\.\d+$/) } + end + + def python_cmake_arg(python = Formula["python@3.13"]) + "-DPython3_EXECUTABLE=#{python.opt_libexec}/bin/python" + end + + def install + rpaths = [ + rpath, + rpath(source: lib/"gz-sim-10/plugins", target: lib), + rpath(source: lib/"gz-sim-10/plugins/gui", target: lib), + rpath(source: lib/"gz-sim-10/plugins/gui/GzSim", target: lib), + ] + cmake_args = std_cmake_args + cmake_args << "-DBUILD_TESTING=OFF" + cmake_args << "-DCMAKE_INSTALL_RPATH=#{rpaths.join(";")}" + cmake_args << python_cmake_arg + + mkdir "build" do + system "cmake", "..", *cmake_args + system "make", "install" + end + + python = pythons.first + # remove @ from formula name + python_name = python.name.tr("@", "") + (lib/"#{python_name}/site-packages").install Dir[lib/"python/*"] + rmdir prefix/"lib/python" + end + + test do + require "system_command" + extend SystemCommand::Mixin + # test some plugins in subfolders + plugin_info = lambda { |p| + # Use gz-plugin --info command to check plugin linking + cmd = Formula["gz-plugin3"].opt_libexec/"gz/plugin3/gz-plugin" + args = ["--info", "--plugin"] << p + # print command and check return code + system cmd, *args + # check that library was loaded properly + _, stderr = system_command(cmd, args:) + error_string = "Error while loading the library" + assert stderr.exclude?(error_string), error_string + } + %w[altimeter log physics sensors].each do |system| + plugin_info.call lib/"gz-sim-10/plugins/libgz-sim-#{system}-system.dylib" + end + ["libAlignTool", "libEntityContextMenuPlugin", "libGzSceneManager", "GzSim/libEntityContextMenu"].each do |p| + plugin_info.call lib/"gz-sim-10/plugins/gui/#{p}.dylib" + end + # test gz sim CLI tool + ENV["GZ_CONFIG_PATH"] = "#{opt_share}/gz" + system Formula["gz-tools2"].opt_bin/"gz", + "sim", "-s", "--iterations", "5", "-r", "-v", "4" + # build against API + (testpath/"test.cpp").write <<-EOS + #include + #include + #include + #include + #include + + using namespace gz; + using namespace sim; + + ////////////////////////////////////////////////// + int main(int argc, char **argv) + { + // Warm start. Initial allocation of resources can throw off calculations. + { + // Create the entity component manager + EntityComponentManager mgr; + + // Create the matching entities + for (int i = 0; i < 100; ++i) + { + Entity entity = mgr.CreateEntity(); + mgr.CreateComponent(entity, components::World()); + mgr.CreateComponent(entity, components::Name("world_name")); + } + + mgr.Each( + [&](const Entity &, const components::World *, + const components::Name *)->bool {return true;}); + } + + return 0; + } + EOS + (testpath/"CMakeLists.txt").write <<-EOS + cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR) + find_package(gz-sim10 QUIET REQUIRED) + add_executable(test_cmake test.cpp) + target_link_libraries(test_cmake gz-sim10::core) + EOS + # ENV.append_path "PKG_CONFIG_PATH", Formula["qt@5"].opt_lib/"pkgconfig" + # system "pkg-config", "--cflags", "gz-sim10" + # cflags = `pkg-config --cflags gz-sim10`.split + # ldflags = `pkg-config --libs gz-sim10`.split + # system ENV.cc, "test.cpp", + # *cflags, + # *ldflags, + # "-lc++", + # "-o", "test" + # system "./test" + # test building with cmake + ENV.append_path "CMAKE_PREFIX_PATH", Formula["qt@5"].opt_prefix + mkdir "build" do + system "cmake", ".." + system "make" + system "./test_cmake" + end + # check for Xcode frameworks in bottle + cmd_not_grep_xcode = "! grep -rnI 'Applications[/]Xcode' #{prefix}" + system cmd_not_grep_xcode + # check python import + pythons.each do |python| + system python.opt_libexec/"bin/python", "-c", "import gz.sim10" + end + end +end