Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make blake3 C library usable as meson subproject #346

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nirs
Copy link

@nirs nirs commented Sep 18, 2023

The meson build system[1] support subprojects - a way to use another project in your build. The blake3 C library can be used like this, but meson requires that the subproject root directory has either meson.build (for meson projects) or CMakeLists.txt (meson can build cmake projects).

Add CMakeLists.txt in the root directory with the project info, including the c subdirectory. With this you can add blake3 as subproject to a meson project.

Example wrap file (using test release from my fork):

% cat subprojects/blake3.wrap
[wrap-file]
directory = BLAKE3-1.4.1-cmake
source_url = https://github.com/nirs/BLAKE3/archive/refs/tags/1.4.1-cmake.tar.gz
source_filename = BLAKE3-1.4.1-cmake.tar.gz
source_hash = 6c6f053ede700d76d12a7ced7bbd640e7a47f97122fe4cbe718aa9406251d043

With this wrap file, you can use blake3 in your meson project[2] like this:

% cat meson.build
project('blake3-meson', 'c', default_options: ['buildtype=release'])
cmake = import('cmake')
blake3_subproj = cmake.subproject('blake3')
blake3_dep = blake3_subproj.dependency('blake3')
executable(example, ['example.c'], dependencies: blake3_dep)

[1] https://mesonbuild.com/
[2] https://github.com/nirs/blake3-meson

@nirs
Copy link
Author

nirs commented Sep 18, 2023

I also started to work on adding meson build system, but it requires more work:
https://github.com/nirs/BLAKE3/tree/meson

Reusing the existing cmake build is more practical.

@oconnor663
Copy link
Member

Is there no way to tell Meson to look in the c/ subdirectory? I've been thinking about cleaning up the root so that everything's under c/, rust/, etc. This feels like moving in other direction.

@nirs
Copy link
Author

nirs commented Sep 20, 2023

Is there no way to tell Meson to look in the c/ subdirectory?

Unfortunately no, it requires build files at the root.

I've been thinking about cleaning up the root so that everything's under c/, rust/, etc. This feels like moving in other direction.

Moving everything but the build files sounds like a good idea. It is nice that the you can do everything from the root, and it make the project more friendly to various tools.

The meson build system[1] support subprojects - a way to use another
project in your build. The blake3 C library can be used like this, but
meson requires that the subproject root directory has either
`meson.build` (for meson projects) or `CMakeLists.txt` (meson can build
cmake projects).

Add `CMakeLists.txt` in the root directory with the project info,
including the `c` subdirectory. With this you can add blake3 as
subproject to a meson project.

Example wrap file (using test release from my fork):

    % cat subprojects/blake3.wrap
    [wrap-file]
    directory = BLAKE3-1.4.1-cmake
    source_url = https://github.com/nirs/BLAKE3/archive/refs/tags/1.4.1-cmake.tar.gz
    source_filename = BLAKE3-1.4.1-cmake.tar.gz
    source_hash = 6c6f053ede700d76d12a7ced7bbd640e7a47f97122fe4cbe718aa9406251d043

With this wrap file, you can use blake3 in your meson project[2] like this:

    % cat meson.build
    project('blake3-meson', 'c', default_options: ['buildtype=release'])
    cmake = import('cmake')
    blake3_subproj = cmake.subproject('blake3')
    blake3_dep = blake3_subproj.dependency('blake3')
    executable(example, ['example.c'], dependencies: blake3_dep)

[1] https://mesonbuild.com/
[2] https://github.com/nirs/blake3-meson
@BurningEnlightenment
Copy link
Collaborator

If we were to go with this, I would prefer moving the whole CMakeLists.txt to the root directory. Our CMakeLists.txt is less than 200 lines long, therefore I think splitting would decrease readability for no benefit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants