Entt: Homebrew formula

Created on 22 Apr 2018  路  33Comments  路  Source: skypjack/entt

Have you considered making your library a Homebrew package to ease updating the library?

I read some of the documentation and I've tried to make this is easy as possible for you because I really want this to happen.

Homebrew is the most popular macOS command-line package manager. I don't think you actually need to run homebrew in order to create and update a package.

The first thing you'll have to do is create a formula definition file. This is a Ruby class that contains the name, description, download URL, test scripts and install scripts.

class Entt < Formula
  desc "Fast and reliable entity-component system and much more"
  homepage "https://skypjack.github.io/entt/"
  url "https://github.com/skypjack/entt/archive/v2.5.0.tar.gz"
  sha256 "6246501c6589eba9832538c47a23a239eaa1066c77471cae7d79e741141ade82"

  def install
    include.install "src/entt"
  end

  test do
    # build the tests
    cd "test"
    mkdir "build"
    cd "build"
    system "cmake", ".."

    # run the tests
    # return 0 if all of the tests succeeded

    # alternatively, you could just put all of this into a script and then just
    # system "./run_tests.sh"
    # make sure that the exit code of the script is 0 if all of the tests passes and 1 otherwise
  end
end

This is a complete (apart from the tests) and working formula file. I created it on my machine and ran brew install entt. Homebrew downloaded the files and installed them for me. All that you have to do is create a test script that builds and runs all of the tests.

Every time you create a new release (like 2.5.1 for example) you'll have to update the url to the tar.gz file in the release and update the sha256 hash.

The formula file lives in the homebrew-core repository so every time you increment the version number you'll have to create a pull request on the homebrew-core repository.

For more information you can read the docs or contact nlohmann who distributes a very popular header-only C++ library on homebrew.

discussion help wanted

Most helpful comment

Sure, I'll be glad to. This is a fantastic library by the way.

All 33 comments

All that you have to do is create a test script that builds and runs all of the tests.

Why not make && make test? It should compile and run tests as expected. Did you try it?
The main problem is that I cannot test it, so I need help to finalize everything. Would you mind to help me with this?

I had a lot of trouble trying to get the tests to run.

So after a few frustrating hours I decided to try and run the tests myself without homebrew doing it for me. Then cmake spat out a whole lot of error messages at me

CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.11)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
CMake Warning (dev) at CMakeLists.txt:107 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "resource" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:117 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "signal" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:96 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "process" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:86 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "locator" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:60 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "core" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at CMakeLists.txt:72 (add_executable):
  Policy CMP0028 is not set: Double colon in target name means ALIAS or
  IMPORTED target.  Run "cmake --help-policy CMP0028" for policy details.
  Use the cmake_policy command to set the policy and suppress this warning.

  Target "entity" links to target "Threads::Threads" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
This warning is for project developers.  Use -Wno-dev to suppress it.

I think it's best to just leave the tests out of the package because I don't really think they are necessary.

If you don't mind excluding the tests then I'll create the initial pull request on homebrew-core

I see. The problem is that you are doing something like this, right?

cd test
mkdir build
cd build
cmake ..
make

CMake is thought so that you must start from the root directory instead. Something along this line:

mkdir build
cd build
cmake ...
make

That is, you must create the build directory within the root directory and not within test.

The README contains a few notes about how to build tests.
Let me know if it works fine for you this way. It should, actually. Travis compiles everything on osx with no problems at all.

Ooooh, I see. I was wondering why there were two CMakeLists.txt files! I just ran the tests successfully. Now I just need to edit the formula to run the tests in this way.

Good to know!! make && make test should work. Doesn't it?
make test doesn't compile anything. Instead it launches tests. This is how ctest works. ;-)

I've edited the formula to run the tests. Running the tests with Homebrew is not as simple as just make && make test. There's a lot of fumbling around. I had to copy files all of the place to finally get it to work. Now that the tests are running, I'll create a pull request on homebrew-core to add the formula.

That's good!! Thank you, really appreciated.
Would you mind to keep an eye on the project and update the formula as soon as new versions are released? Someone is already doing it for vcpkg. Help from users of the library is highly appreciated. :-)

Sure, I'll be glad to. This is a fantastic library by the way.

Thank you. I'm glad you find it _fantastic_.
A lot of things are the result of suggestions or requests made by the users, so feel free to participate whenever you want. Your help is invaluable!!

Keep also an eye on the branch experimental. I'm working on the v3 and adding a lot of new features. Unfortunately it will take a while for I'm doing it for free in my free time, but sooner or later I'll release the new version. ;-)


If I can help you with Homebrew, let me know.
Otherwise, feel free to close the issue when you're done. I don't think there is much to say my side now.

Thank you once more for your help.

I'm adding you to the contributors list (branch experimental). Thank you very much for your help so far.

Hi @Kerndog73 any news on this?

The formula is in the process of being approved. This is the pull request. I couldn't get the main tests to work inside Homebrew so I wrote a very simple test. Now I'm trying to create an option that builds and installs the HTML docs. I just found out how to do this so I will commit to the pull request shortly.

Sounds good!! Please, keep me updated and feel free to contact me if you need help.

Homebrew does not accept header-only libraries. The pull request was closed. I could create an external tap.

Didn't they accept json from nlohmann? It's header-only. Am I wrong?

It turns out that nlohmann created his own tap.

Creating a tap involves creating a new Github repo and putting the formula file inside it. There's no approval process. Once the repo is created, the package can be installed straight away. Then the user types

brew install Kerndog73/entt/entt

I don't really want to be the creator of the repo because that will mean people see my name when they install the library instead of yours. I think you should be the creator of the repo so that people can type

brew install skypjack/entt/entt

to install the library. The formula has already been tested on a mac and all future changes will just be incrementing version numbers.

What do you think about this?

Perhaps you could own the repo and I could send a pull request to change it every so often. I just realized that the SHA-256 checksum has to be computed which is kind of a hassle. Or perhaps I could commit directly to the repo. Is that possible?

What repo? EnTT? Uhm... a PR? :-)
I didn't understand what repo _I could own_ anyway, I'm sorry. I think I missed you along the path. What are you speaking about?

To create a tap. We'll create a repo called homebrew-entt. This creates a tap called entt. A tap is simply a repo full of formulas. We'll put the entt.rb file into the entt tap so that the library can be installed by specifying the owner of the tap (skypjack or Kerndog73), the name of the tap (entt) and the name of the formula (entt). Like this brew install skypjack/entt/entt.

Ok, so a new repo. Nothing to do on EnTT, did I get it?
Fine for me, I can create the repo within my account and give you access if you want. Otherwise, you can create it in your account and I can mention the repo in the README file.
Both the solutions are fine for me, so it's up to you to decide. I'm at your disposal. :-)

Alright so, I think you should create the repo (homebrew-entt) and then give me access. That way, people write your name when installing the library and I can make sure the formula is working without bothering you with a bunch of PRs. Sound good?

Fine for me. Is an empty repo fine for you? I'm not that sure about how to init it, so...
If you know how to fill it, I would create an empty project and give you access to it and that's all.

Empty is fine

Here it is. Let's see if it works. :-)
Keep me updated on your progresses, please. Thank you very much for your help!!

I added the file. I tested it a bunch of times and I seems to be working!!!

You might want to say that EnTT can be installed like this brew install skypjack/entt/entt in the README

Can I ask you why the double entt in skypjack/entt/entt? It looks weird.

The first entt is the name of the tap. It refers to the homebrew-entt repo.
The second entt is the name of the formula. It refers to the entt.rb file in the repo.

It make sense. Thank you.
So, what can I write in the README file of EnTT to help users using it?
If you can help me finding the right words... Imagine to have to explain it to me that know anything about homebrew, how would you do that? :-)

Maybe write something like this:

EnTT is available as a homebrew formula. Just type brew install skypjack/entt/entt to install.

What about adding a README file to homebrew-entt with a few instructions? Does it break everything?
The EnTT repository could just mention and link the other repository this way.

Instructions aren鈥檛 really necessary. Homebrew is just a tool to make installing the library more convenient. If you already have Homebrew installed, installing new libraries is convenient. Also, if you have Homebrew installed then you know how it works and all you need is brew install skypjack/entt/entt.

If you don鈥檛 have Homebrew installed, you鈥檒l need instructions but it is more convenient to just clone the repo than to download Homebrew, learn how to use it and then install the library.

EnTT is likely to be discovered from the skypjack/entt repo so it makes more sense to put all the information in its README. skypjack/homebrew-entt isn鈥檛 intended to be discovered, viewed or contain any information. skypjack/homebrew-entt just holds the entt.rb file. That鈥檚 it.

It makes sense. Updated the README file - caa8d16.
Thank you very much once more for your help. Really appreciated.
If you can keep the formula updated with the future versions it would be great!!


We can close the issue from my point of view. Anything else your side?

Was this page helpful?
0 / 5 - 0 ratings