Skip to content

Commit

Permalink
setup new formula file for freecad 0.20.2 release using py310
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatch committed Apr 23, 2024
1 parent b619f58 commit 0e6d269
Showing 1 changed file with 322 additions and 0 deletions.
322 changes: 322 additions & 0 deletions Formula/[email protected]_py310.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
class FreecadAT0202Py310 < Formula
desc "Parametric 3D modeler"
homepage "https://www.freecadweb.org"
url "https://github.com/FreeCAD/FreeCAD/archive/refs/tags/0.20.2.tar.gz"
sha256 "46922f3a477e742e1a89cd5346692d63aebb2b67af887b3e463e094a4ae055da"
license "GPL-2.0-only"
head "https://github.com/freecad/FreeCAD.git", branch: "main", shallow: false

keg_only :versioned_formula

depends_on "cmake" => :build
depends_on "gcc" => :build
# epends_on "hdf5-mpi" => :build # requires fortran compiler
depends_on "hdf5" => :build # requires fortran compiler
# epends_on "llvm" => :build
depends_on "mesa" => :build if OS.linux?
depends_on "ninja" => :build
depends_on "pkg-config" => :build
depends_on "[email protected]" => :build
depends_on "swig" => :build
depends_on "tbb" => :build
depends_on "boost"
depends_on "cython"
depends_on "doxygen"
depends_on "freecad/freecad/coin3d_py310"
depends_on "freecad/freecad/fc_bundle"
depends_on "freecad/freecad/med-file"
depends_on "freecad/freecad/[email protected]_py310"
depends_on "freecad/freecad/pybind11_py310"
depends_on "freecad/freecad/[email protected]_py310"
depends_on "freecad/freecad/[email protected]_py310"
depends_on "freetype"
depends_on "glew"
depends_on "icu4c"
depends_on macos: :high_sierra # no access to sierra test box
depends_on "openblas"
depends_on "opencascade"
depends_on "orocos-kdl"
# epends_on "freecad/freecad/[email protected]"
# TODO: is it possible to point qt@5 to a revision where py310 is being used
depends_on "qt@5"
# epends_on "svn"
depends_on "vtk"
depends_on "webp"
depends_on "xerces-c"
depends_on "zlib"

# NOTE: `brew update-python-resources` check for outdated py resources
# TODO: ipatch, still appears freecad's cmake setup process is not finding matplotlib
resource "matplotlib" do
url "https://files.pythonhosted.org/packages/8a/46/425a44ab9a71afd2f2c8a78b039c1af8ec21e370047f0ad6e43ca819788e/matplotlib-3.5.1.tar.gz"
sha256 "b2e9810e09c3a47b73ce9cab5a72243a1258f61e7900969097a817232246ce1c"
end

resource "PyYAML" do
url "https://files.pythonhosted.org/packages/36/2b/61d51a2c4f25ef062ae3f74576b01638bebad5e045f747ff12643df63844/PyYAML-6.0.tar.gz"
sha256 "68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2"
end

# NOTE: https://docs.brew.sh/Formula-Cookbook#handling-different-system-configurations
# patch for mojave with 10.15 SDK
patch :p1 do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/a4b71def99b5fe907550729038752aaf6fa1b9bf/patches/freecad-0.20.1-macos-10.15-sdk.patch"
sha256 "ce9f4b2afb2c621274e74208a563616eeeee54369f295b6c5f6f4f3112923135"
end

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/06bd260fc8c8bce1c283f86df3641fd2efea186d/patches/freecad-0.20.2-e57-add-missing-include.patch"
sha256 "83f033112845fde21c84f18bfa91609b18394dc9adb268c24aa8a1e5ec5aca85"
end

# newer versions of occ have removed offending header file
patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/06bd260fc8c8bce1c283f86df3641fd2efea186d/patches/freecad-0.20.2-occ-error.patch"
sha256 "e345d1ced6e46dd6d7cdaa136d32a8fe55eb54ccb01468f22fb425645e5a0585"
end

patch do
# NOTE: ipatch, ie. local patch `url "file:///#{HOMEBREW_PREFIX}/Library/Taps/freecad/homebrew-freecad/patches/`
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/06bd260fc8c8bce1c283f86df3641fd2efea186d/patches/freecad-0.20.2-setup-python-cmake.patch"
sha256 "f259ec18294438a306fa58599c093d18bc9aaf3cb8056d140c15fdfe9247957a"
end

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/1fde4f693950d77e8617c08921d50c1aba3f0a56/patches/freecad-0.20.2-cmake-find-xercesc.patch"
sha256 "adb30f5d723672d1d54db4a236bce8a85e9bc9d0667ef88a7360e4cae1bb27c9"
end

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/95e5aa838ae8b5e7d4fd6ddd710bc53c8caedddc/patches/freecad-0.20.2-cmake-find-hdf5.patch"
sha256 "99d115426cb3e8d7e5ab070e1d726e51eda181ac08768866c6e0fd68cda97f20"
end

patch do
url "https://raw.githubusercontent.com/FreeCAD/homebrew-freecad/95e5aa838ae8b5e7d4fd6ddd710bc53c8caedddc/patches/freecad-0.20.2-vtk-9.3.patch"
sha256 "67794ebfcd70a160d379eeca7d2ef78d510057960d0eaa4e2e345acb7ae244aa"
end

def install

Check failure on line 99 in Formula/[email protected]_py310.rb

View workflow job for this annotation

GitHub Actions / test-bot (macos-12)

`brew install --verbose --build-bottle freecad/freecad/[email protected]_py310` failed on macOS Monterey (12)!

on of undefined template 'std::array<std::pair<double, std::string>, 3>' auto pts = schemaTranslatePoint(x, y, z, 1e-7); ^ /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__tuple:219:64: note: template is declared here template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array; ^ In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/Mod/Fem/App/HypothesisPy.cpp:30: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/StdMeshers_CompositeSegment_1D.hxx:30: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/StdMeshers_Regular_1D.hxx:34: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMESH_Algo.hxx:33: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_MeshNode.hxx:32: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_MeshElement.hxx:36: /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_StdIterator.hxx:37:38: warning: 'iterator<std::input_iterator_tag, const SMDS_MeshNode *>' is deprecated [-Wdeprecated-declarations] class SMDS_StdIterator : public std::iterator< std::input_iterator_tag, VALUE > ^ /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_MeshElement.hxx:81:12: note: in instantiation of template class 'SMDS_StdIterator<const SMDS_MeshNode *, boost::shared_ptr<SMDS_Iterator<const SMDS_MeshElement *>>>' requested here iterator begin_nodes() const { return iterator( nodesIterator() ); } ^ /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__iterator/iterator.h:27:29: note: 'iterator<std::input_iterator_tag, const SMDS_MeshNode *>' has been explicitly marked deprecated here struct _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 iterator ^ /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__config:1066:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX17' # define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED ^ /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include/c++/v1/__config:1043:48: note: expanded from macro '_LIBCPP_DEPRECATED' # define _LIBCPP_DEPRECATED __attribute__ ((deprecated)) ^ 1 error generated. In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/Mod/Fem/App/HypothesisPy.cpp:43: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/StdMeshers_Prism_3D.hxx:34: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMESHDS_Mesh.hxx:32: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_Mesh.hxx:45: In file included from /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_VtkVolume.hxx:26: /tmp/freecadA0.20.2_py310-20240424-20392-io0ek8/FreeCAD-0.20.2/src/3rdParty/salomesmesh/inc/SMDS_UnstructuredGrid.hxx:99:39: warning: 'GetCellLinks' is deprecated: Use GetLinks() instead. [-Wdeprecated-declarations] return static_cast<vtkCellLinks*>(GetCellLinks()); ^ /usr/local/opt/vtk/include/vtk-9.3/vtkUnstructuredGrid.h:289:3: note: 'GetCellLinks' has been explicitly marked deprecated here VTK_DEPRECATED_IN_9_3_0("Use GetLinks() instead.") ^ /usr/local/opt/vtk/include/vtk-9.3/vtkDeprecation.h:99:41: note: expanded from macro 'VTK_DEPRECATED_IN_9_3_0' #define VTK_DEPRECATE
hbp = HOMEBREW_PREFIX

# NOTE: taken from node@14 formula, node uses autoconf and not cmake
# make sure subprocesses spawned by make are using our Python 3
#
# NOTE: `which` cmd is not installed by default on some OSes
# ENV["PYTHON"] = which("python3.10")
#
# Get the Python includes directory without duplicates
ENV["PYTHON"] = Formula["[email protected]"].opt_bin/"python3.10"

py_inc_output = `python3.10-config --includes`
py_inc_dirs = py_inc_output.scan(/-I([^\s]+)/).flatten.uniq
py_inc_dir = py_inc_dirs.join(" ")

py_lib_path = `python3.10-config --configdir`.strip + "/libpython3.10.dylib"

puts "--------------------------------------------"
puts "PYTHON=#{ENV["PYTHON"]}"
puts "PYTHON_INCLUDE_DIR=#{py_inc_dir}"
puts "PYTHON_LIBRARY=#{py_lib_path}"

# NOTE: apple's clang & clang++ don not provide batteries for open-mpi
# NOTE: when setting the compilers to brews' llvm, set the cmake_ar linker as well
# ENV["CC"] = Formula["llvm"].opt_bin/"clang"
# ENV["CXX"] = Formula["llvm"].opt_bin/"clang++"

# NOTE: ipatch, attempt to nuke default cmake_prefix_path to prevent qt6 from sneaking in
ENV.delete("CMAKE_PREFIX_PATH") # Clear existing paths
puts "--------------------------------------------"
puts "CMAKE_PREFIX_PATH=#{ENV["CMAKE_PREFIX_PATH"]}"
puts "CMAKE_PREFIX_PATH Datatype: #{ENV["CMAKE_PREFIX_PATH"].class}"
puts "--------------------------------------------"
puts "homebrew prefix: #{hbp}"
puts "prefix: #{prefix}"
puts "rpath: #{rpath}"

ENV.remove "PATH", Formula["qt"].opt_prefix/"bin"
ENV.remove "PATH", Formula["pyqt"].opt_prefix/"bin"
puts "PATH=#{ENV["PATH"]}"
puts "--------------------------------------------"

cmake_prefix_paths = []
cmake_prefix_paths << Formula["pybind11_py310"].prefix
cmake_prefix_paths << Formula["doxygen"].prefix
cmake_prefix_paths << Formula["xerces-c"].prefix
cmake_prefix_paths << Formula["zlib"].prefix
cmake_prefix_paths << Formula["opencascade"].prefix
cmake_prefix_paths << Formula["vtk"].prefix
cmake_prefix_paths << Formula["utf8cpp"].prefix
cmake_prefix_paths << Formula["glew"].prefix
cmake_prefix_paths << Formula["hdf5"].prefix
cmake_prefix_paths << Formula["libpng"].prefix
cmake_prefix_paths << Formula["pugixml"].prefix
cmake_prefix_paths << Formula["eigen"].prefix
cmake_prefix_paths << Formula["expat"].prefix
cmake_prefix_paths << Formula["double-conversion"].prefix
cmake_prefix_paths << Formula["lz4"].prefix
cmake_prefix_paths << Formula["xz"].prefix
cmake_prefix_paths << Formula["libjpeg-turbo"].prefix
cmake_prefix_paths << Formula["libtiff"].prefix
cmake_prefix_paths << Formula["medfile"].prefix
cmake_prefix_paths << Formula["pkg-config"].prefix
cmake_prefix_paths << Formula["boost"].prefix
cmake_prefix_paths << Formula["[email protected]"].prefix
cmake_prefix_paths << Formula["freetype"].prefix
cmake_prefix_paths << Formula["coin3d_py310"].prefix
cmake_prefix_paths << Formula["qt@5"].prefix
# cmake_prefix_paths << Formula["open-mpi"].prefix
cmake_prefix_paths << Formula["[email protected]_py310"].prefix
cmake_prefix_paths << Formula["[email protected]_py310"].prefix
# cmake_prefix_paths << Formula["svn"].prefix
# cmake_prefix_paths << Formula["llvm"].prefix
cmake_prefix_paths << Formula["tbb"].prefix

cmake_prefix_path_string = cmake_prefix_paths.join(";")

apl_sdk = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
apl_frmwks ="#{apl_sdk}/System/Library/Frameworks"

# TODO: stub out the below cmake vars
# -DCMAKE_OSX_DEPLOYMENT_TARGET=
# -DCMAKE_OSX_ARCHITECTURES=
# -DCMAKE_OSX_SYSROOT=#{cmake_osx_sysroot}
# -DCMAKE_LINKER
# -DCMAKE_LINKER=#{hbp}/opt/llvm/bin/lld
# -DCMAKE_CXX_FLAGS="-fuse-ld=lld"
# -DCMAKE_INSTALL_RPATH=#{prefix}/lib
# -DCMAKE_INSTALL_RPATH=#{rpath}
# -DCMAKE_AR=#{hbp}/opt/llvm/bin/llvm-ar
# -DCMAKE_INSTALL_NAME_TOOL:FILEPATH=CMAKE_INSTALL_NAME_TOOL-NOTFOUND
# -DBUILD_DRAWING=1
# -DBUILD_SMESH=1
# -DBUILD_ENABLE_CXX_STD=C++17
# -DFREECAD_USE_EXTERNAL_KDL=1
# -DBUILD_FEM_NETGEN=0
# -DBUILD_QT5=1
# -DFREECAD_USE_QTWEBMODULE=#{qtwebmodule}

if OS.mac?
args_macos_only = %W[
-DCMAKE_AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar
-DCMAKE_INSTALL_NAME_TOOL:FILEPATH=/usr/bin/install_name_tool
-DCMAKE_LINKER=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
-DOPENGL_INCLUDE_DIR=#{apl_frmwks}/OpenGL.framework
-DOPENGL_gl_LIBRARY=#{apl_frmwks}/OpenGL.framework
-DOPENGL_GLU_INCLUDE_DIR=#{apl_frmwks}/OpenGL.framework
-DOPENGL_glu_LIBRARY=#{apl_frmwks}/OpenGL.framework

-D_Qt5UiTools_RELEASE_AppKit_PATH=#{apl_frmwks}/AppKit.framework
-D_Qt5UiTools_RELEASE_Metal_PATH=#{apl_frmwks}/Metal.framework
-D_Qt5UiTools_RELEASE_DiskArbitration_PATH=#{apl_frmwks}/DiskArbitration.framework
-D_Qt5UiTools_RELEASE_IOKit_PATH=#{apl_frmwks}/IOKit.framework
-D_Qt5UiTools_RELEASE_OpenGL_PATH=#{apl_frmwks}/OpenGL.framework
-D_Qt5UiTools_RELEASE_AGL_PATH=#{apl_frmwks}/AGL.framework
]
end

args = %W[
-DHOMEBREW_PREFIX=#{hbp}
-DCMAKE_PREFIX_PATH=#{cmake_prefix_path_string}
-DCMAKE_INSTALL_PREFIX=#{prefix}
-DCMAKE_VERBOSE_MAKEFILE=1
-DPYTHON_EXECUTABLE=#{hbp}/opt/[email protected]/bin/python3.10
-DPYTHON_INCLUDE_DIR=#{py_inc_dir}
-DPYTHON_LIBRARY=#{py_lib_path}
-DFREECAD_USE_PYBIND11=1
-DCMAKE_BUILD_TYPE=RelWithDebInfo

-DCMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH=FALSE
-DCMAKE_FIND_USE_CMAKE_SYSTEM_PATH=FALSE

-DCMAKE_IGNORE_PATH=#{hbp}/lib;#{hbp}/include/QtCore;#{hbp}/Cellar/qt;
-L
]
# NOTE: useful cmake debugging args
# --trace
# -L

ENV.remove "PATH", Formula["pyside@2"].opt_prefix/"bin"
ENV.remove "PATH", Formula["qt"].opt_prefix/"bin"
ENV.remove "PATH", Formula["pyqt"].opt_prefix/"bin"

ENV.remove "PKG_CONFIG_PATH", Formula["pyside@2"].opt_prefix/"lib/pkgconfig"
ENV.remove "PKG_CONFIG_PATH", Formula["qt"].opt_prefix/"lib/pkgconfig"

ENV.remove "CMAKE_FRAMEWORK_PATH", Formula["qt"].opt_prefix/"Frameworks"

# TODO: ipatch, causes audit exception, ie. `brew style freecad/freecad`
# ENV.remove "PATH", Formula["[email protected]"].opt_prefix/"bin"
# ENV.remove "PATH", Formula["[email protected]"].opt_prefix/"libexec/bin"
# ENV.remove "PKG_CONFIG_PATH", Formula["[email protected]"].opt_prefix/"lib/pkgconfig"

# NOTE: ipatch, required for successful build
# ENV.prepend_path "PYTHONPATH", Formula["[email protected]"].opt_prefix/Language::Python.site_packages(python3)
# ENV.prepend_path "PYTHONPATH", Formula["[email protected]"].opt_prefix/Language::Python.site_packages(python3)

# NOTE: ipatch, do not make build dir a sub dir of the src dir
puts "current working directory: #{Dir.pwd}"
src_dir = Dir.pwd.to_s
parent_dir = File.expand_path("..", src_dir)
build_dir = "#{parent_dir}/build"
# Create the build directory if it doesn't exist
mkdir_p(build_dir)
# Change the working directory to the build directory
# false positive: `warning: conflicting chdir during another chdir block`
Dir.chdir(build_dir)
puts "----------------------------------------------------"
puts Dir.pwd
puts "----------------------------------------------------"

if OS.mac?
system "cmake", *args, *args_macos_only, src_dir.to_s
else
system "cmake", "-G", "Ninja", *args, src_dir.to_s
end
system "cmake", "--build", build_dir.to_s
system "cmake", "--install", build_dir.to_s
end

# NOTE: reenable after successful build
# def post_install
# if OS.mac?
# ohai "the value of prefix = #{prefix}"
# ln "#{prefix}/MacOS/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad", force: true
# ln "#{prefix}/MacOS/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd", force: true
# elsif OS.linux?
# ohai "the value of prefix = #{prefix}"
# ln "#{bin}/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad", force: true
# ln "#{bin}/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd", force: true
# end
# end

def caveats
<<-EOS
After installing FreeCAD you may want to do the following:
1. Due to recent code signing updates with Catalina and newer
building a FreeCAD.app bundle using the existing python
script no longer works due to updating the rpaths of the
copied executables and libraries into a FreeCAD.app
bundle. Until a fix or work around is made freecad
is built for CLI by default now.
2. if freecad launches with runtime errors a common fix
i use is to force link [email protected] and
[email protected] so workbenches such Draft and Arch
have the necessary runtime deps, see brew documenation
about force linking the above packages
4. upstream homebrew/core has begun to introduce python 3.11
with that said, testing the formula manually on my local
catalina box i ran into issues with regard to boost.
the quick fix, unlink python 3.11 and cmake is able to
finish its checks and the build process can begin
EOS
end

test do
# NOTE: make test more robust and accurate
system "true"
end
end

0 comments on commit 0e6d269

Please sign in to comment.