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

Add libsndio recipe #23087

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions recipes/libsndio/all/conandata.yml
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"
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

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!

sha256: "4e8d77069b651d7c4bb2a50ba49004bd7fcfdfec1516f88a76457f831c17a546"
"license":
url: "https://raw.githubusercontent.com/ratchov/sndio/e10e4f836b88f8d5ea2864845e3712f560e6bed6/LICENSE"
sha256: "4ae392ab9cfbf2d6ac8522f5f4b025685d60c824979fad783aaf72d55165730f"
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
153 changes: 153 additions & 0 deletions recipes/libsndio/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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."
spiderkeys marked this conversation as resolved.
Show resolved Hide resolved
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 != "Linux":
spiderkeys marked this conversation as resolved.
Show resolved Hide resolved
raise ConanInvalidConfiguration(f"{self.ref} only supports Linux")

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")

# Inject conan dependency information into sndio configuration
spiderkeys marked this conversation as resolved.
Show resolved Hide resolved
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"
7 changes: 7 additions & 0 deletions recipes/libsndio/all/test_package/CMakeLists.txt
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)
26 changes: 26 additions & 0 deletions recipes/libsndio/all/test_package/conanfile.py
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")
24 changes: 24 additions & 0 deletions recipes/libsndio/all/test_package/test_package.c
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;
}
3 changes: 3 additions & 0 deletions recipes/libsndio/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.9.0":
folder: "all"
Loading