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 Mar 14, 2024
1 parent 95e5aa8 commit 1bd0eaf
Showing 1 changed file with 227 additions and 0 deletions.
227 changes: 227 additions & 0 deletions Formula/[email protected]_py310.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
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

depends_on "cmake" => :build
depends_on "gcc" => :build
# depends_on "hdf5-mpi" => :build # requires fortran compiler

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

View workflow job for this annotation

GitHub Actions / test-bot (macos-14)

FormulaAudit/Comments: Commented-out dependency "hdf5-mpi" => :build # requires fortran compiler

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

View workflow job for this annotation

GitHub Actions / test-bot (macos-13)

FormulaAudit/Comments: Commented-out dependency "hdf5-mpi" => :build # requires fortran compiler

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

View workflow job for this annotation

GitHub Actions / test-bot (macos-12)

FormulaAudit/Comments: Commented-out dependency "hdf5-mpi" => :build # requires fortran compiler
depends_on "hdf5" => :build # requires fortran compiler
depends_on "llvm" => :build
depends_on "mesa" => :build if OS.linux?
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 "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"
depends_on "vtk"
depends_on "webp"
depends_on "xerces-c"

# 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/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
# NOTE: ordered loosely by cmake checks
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
# TODO: set var in a more robust way, rm dep on which
ENV["PYTHON"] = which("python3.10")
puts "--------------------------------------------"
puts "PYTHON=#{ENV["PYTHON"]}"
puts "--------------------------------------------"

ENV["CC"] = Formula["llvm"].opt_bin/"clang"
ENV["CXX"] = Formula["llvm"].opt_bin/"clang++"

ENV.append_path "CMAKE_PREFIX_PATH", Formula["coin3d_py310"].prefix
# ENV.append_path "CMAKE_PREFIX_PATH", Formula["hdf5"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["llvm"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["med-file"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["mesa"].prefix if OS.linux?
ENV.append_path "CMAKE_PREFIX_PATH", Formula["opencascade"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["[email protected]_py310"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["qt@5"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["vtk"].prefix
ENV.append_path "CMAKE_PREFIX_PATH", Formula["xerces-c"].prefix

# TODO: exp with prepending qt@5 to PATH
ENV.prepend_path "PATH", Formula["qt@5"].opt_bin

# ENV["HDF5_ROOT"] = Formula["hdf5"].prefix
# ENV["HDF5_NO_FIND_PACKAGE_CONFIG_FILE"] = "TRUE"

args = std_cmake_args + %W[
-DHOMEBREW_PREFIX=#{hbp}
-DPYTHON_EXECUTABLE=#{hbp}/opt/[email protected]/bin/python3.10
-DBUILD_SMESH=1
-DBUILD_QT5=1
-DFREECAD_USE_EXTERNAL_KDL=1
-DBUILD_FEM_NETGEN=0
-DBUILD_ENABLE_CXX_STD=C++17
-DFREECAD_USE_PYBIND11=1
-DBUILD_DRAWING=0
-L
]
# -DHDF5_DIR=Formula["hdf5"].prefix
# NOTE: useful cmake debugging args
# --trace
# -L

if OS.mac?
args += %W[
-DPYTHON_INCLUDE_DIR=#{hbp}/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/Headers
-DPYTHON_LIBRARY=#{hbp}/opt/[email protected]/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
]
elsif OS.linux?
args += %W[
-DPYTHON_INCLUDE_DIR=#{hbp}/opt/[email protected]/include/python3.10
-DPYTHON_LIBRARY=#{hbp}/opt/[email protected]/lib/libpython3.10.so
]
else
odie "Unsupported operating system"
end

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"

# for reasons i dont understand pyside@2 is sneaking into the cmake_prefix_path
ENV.remove "CMAKE_PREFIX_PATH", Formula["pyside@2"].prefix
ENV.remove "CMAKE_PREFIX_PATH", HOMEBREW_PREFIX

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

# 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)

# TODO: ipatch, do not make build dir a sub dir of the src dir
mkdir "Build" do
system "cmake", *args, ".."
system "make", "install"
end
end

# TODO: ipatch, the below postinstall steps are only valid for macos, need to update for gnu+linux to
def post_install
if OS.mac?
ohai "the value of prefix = #{prefix}"
ln "#{prefix}/MacOS/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad"
ln "#{prefix}/MacOS/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd"
elsif OS.linux?
ohai "the value of prefix = #{prefix}"
ln "#{bin}/FreeCAD", "#{HOMEBREW_PREFIX}/bin/freecad"
ln "#{bin}/FreeCADCmd", "#{HOMEBREW_PREFIX}/bin/freecadcmd"
end
end

def caveats
<<-EOS
After installing FreeCAD you may want to do the following:
1. Amend your PYTHONPATH environmental variable to point to
the FreeCAD directory
export PYTHONPATH=#{bin}:$PYTHONPATH
2. 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.
3. if freecad launches with runtime errors a common fix
i have run into 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
5. it appears build will fail if qt version 6 is symlinked
into the homebrew prefix ie. /usr/local or /opt/local
EOS
end

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

0 comments on commit 1bd0eaf

Please sign in to comment.