Homebrew-core: MoltenVK formula

Created on 22 Apr 2018  路  5Comments  路  Source: Homebrew/homebrew-core

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:

  • [ ] Get the pkg-config file installed and recognized by the system
  • [ ] Use bottle to reduce installation time (I quite don't understand how to add/test this)
  • [ ] 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.

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

outdated

Most helpful comment

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!

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jyutzler picture jyutzler  路  4Comments

gregvirgin picture gregvirgin  路  3Comments

yuna9 picture yuna9  路  4Comments

tejasmanohar picture tejasmanohar  路  3Comments

bantl23 picture bantl23  路  3Comments