Hi, I'm working to get a working a formula for MoltenVK.
so far I've this
class Moltenvk < Formula
desc "MoltenVK is an implementation of the high-performance, industry-standard Vulkan graphics and compute API, that runs on Apple's Metal graphics framework, bringing Vulkan compatibility to iOS and macOS."
homepage "https://github.com/KhronosGroup/MoltenVK"
url "https://github.com/KhronosGroup/MoltenVK/archive/v1.0.3.zip"
sha256 "c94679265cbd5ba55fd13af6e7bc356c263abb3092a3c67813dae7a22f4e9e37"
depends_on "cmake" => :build
depends_on "python3"
depends_on "ninja"
def install
system "./fetchDependencies"
system "xcodebuild", "-project", "MoltenVKPackaging.xcodeproj", "-scheme", "MoltenVK (Release)", "build"
# $: xcodebuild -project MoltenVKPackaging.xcodeproj GCC_PREPROCESSOR_DEFINITIONS='$GCC_PREPROCESSOR_DEFINITIONS MVK_LOGGING_ENABLED=0' -scheme "MoltenVK (Release)" build
# Merge iOS and macOS MoltenVK lib
system "mkdir", "Package/Release/MoltenVK/lib"
system "lipo", "Package/Release/MoltenVK/macOS/libMoltenVK.dylib", "Package/Release/MoltenVK/iOS/libMoltenVK.dylib", "-output", "Package/Release/MoltenVK/lib/libMoltenVK.dylib", "-create"
# $: lipo Package/Release/MoltenVK/macOS/libMoltenVK.dylib Package/Release/MoltenVK/iOS/libMoltenVK.dylib -output Package/Release/MoltenVK/lib/libMoltenVK.dylib -create
# Clean unused files before move to the installation path
rm_rf "Package/Release/MoltenVK/macOS"
rm_rf "Package/Release/MoltenVK/iOS"
# Create pkg config file
pkgconfig = "lib/pkgconfig/vulkan.pc"
system "mkdir", "-p", "lib/pkgconfig"
system "touch", pkgconfig
system "echo", "prefix=\"/usr/local/Cellar/moltenvk/1.0.1\"", ">>", pkgconfig
system "echo", "exec_prefix=${prefix}", ">>", pkgconfig
system "echo", "libdir=${prefix}/lib", ">>", pkgconfig
system "echo", "includedir=${prefix}/include", ">>", pkgconfig
system "echo", "", ">>", pkgconfig
system "echo", "Name: Vulkan", ">>", pkgconfig
system "echo", "Description: Vulkan SDK", ">>", pkgconfig
system "echo", "Version: 1.0.1", ">>", pkgconfig
system "echo", "Libs: -L${libdir} -lvulkan", ">>", pkgconfig
system "echo", "Cflags: -I${includedir} -I${includedir}/..", ">>", pkgconfig
# ENV.prepend_path "PKG_CONFIG_PATH", "#{Formula["moltenvk"].opt_lib}/pkgconfig"
prefix.install Dir["Package/Release/MoltenVK/*"]
end
test do
# `test do` will create, run in and delete a temporary directory.
#
# This test will fail and we won't accept that! For Homebrew/homebrew-core
# this will need to be a test that verifies the functionality of the
# software. Run the test with `brew test MoltenVK`. Options passed
# to `brew install` such as `--HEAD` also need to be provided to `brew test`.
#
# The installed folder is not in the path, so use the entire path to any
# executables being tested: `system "#{bin}/program", "do", "something"`.
system "false"
end
end
The process works almost as expected, the only issue I'm having is creating and installing the pkg-config file, I don't know or understand well how it works, but I think it is needed so the lib can found for some build systems, but not quite sure.
So will be helpful if someone helps me to resolve this, its quite difficult to address this because the build process (in my laptop) takes 17 mins to complete, so is taking a lot of time to make small changes and try to see if it works.
So what I need to do before submit this formula its:
Also all the feedback is appreciated because I'm not so experience with the formula API and the documentation is not clear in some things (as all the API documentations, and there are so few other resources/examples to learn from).
Regards
The process works almost as expected, the only issue I'm having is creating and installing the pkg-config file, I don't know or understand well how it works, but I think it is needed so the lib can found for some build systems, but not quite sure.
If MoltenVK doesn't provide one, then you don't need to generate one for them. pkg-config is indeed used to discover libraries and headers, but we don't require that every library generate and install one.
Use bottle to reduce installation time (I quite don't understand how to add/test this)
We generate these on our CI when a formula is added -- you don't need to do anything here.
Write a test, I saw in other formulas that I can create a temp C file to test this out and return the result as a process exit value.
Yup, this is how we usually test libraries.
I'd go ahead and open a PR for this formula; that makes reviewing a bit easier.
Thanks!
Thanks, I would submit tomorrow a pull request, want to get the test working first.
system "./fetchDependencies" is not acceptable. We do not allow formulas to download things outside of resource blocks, to allow for Homebrew caching mechanism to operate.
system "lipo" is also not acceptable, we want to provide macOS software. Please drop the iOS part of the build.
Ok then MoltenVK dependencies could be wrapped in formulas in order to drop ./fetchDependencies (this script just download and build the dependencies).
But theres no point to submit this formula if only macOS library is provided, because the library is for iOS and macOS, and having separate methods to install one or the other will defeat the purpose (that I've in mind) of this formula.
the library is for iOS and macOS, and having separate methods to install one or the other will defeat the purpose (that I've in mind) of this formula
Then this is probably a better fit to maintain in a personal tap: https://github.com/Homebrew/brew/blob/master/docs/How-to-Create-and-Maintain-a-Tap.md
Most helpful comment
If MoltenVK doesn't provide one, then you don't need to generate one for them.
pkg-configis indeed used to discover libraries and headers, but we don't require that every library generate and install one.We generate these on our CI when a formula is added -- you don't need to do anything here.
Yup, this is how we usually test libraries.
I'd go ahead and open a PR for this formula; that makes reviewing a bit easier.
Thanks!