You are not logged in.

#1 2020-12-08 19:16:54

erbrecht
Member
From: United States
Registered: 2016-03-07
Posts: 10

building dependency from source when package exists

I've been maintaining noisetorch-git and noistetorch-bin for a little while now, and someone requested a plain 'noisetorch' package that builds the release version from source. They commented that this could potentially be a good candidate for the community repo. Currently the noisetorch project is still only on beta, so according to the packaging guidelines this wouldn't be ready just yet, but it got me thinking about building this package.

Noisetorch relies on librnnoise-ladspa, which it builds from source, but is also available as a stand-alone AUR package. I'm guessing the ideal approach here would be to add a dependency to the librnnoise-ladspa package instead of building it from source within the noisetorch package.

And now I'm also wondering if noisetorch-git should do the same. Does this sound like a reasonable approach, adding the dependency on an existing AUR package, or is there a better method for this?

Offline

#2 2020-12-08 20:16:20

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 24,936
Website

Re: building dependency from source when package exists

erbrecht wrote:

Noisetorch relies on librnnoise-ladspa, which it builds from source, but is also available as a stand-alone AUR package. I'm guessing the ideal approach here would be to add a dependency to the librnnoise-ladspa package instead of building it from source within the noisetorch package.

Yes, if you can get it to work, that would be ideal for both the tagged release and the git build.

As for bulding the tagged release, by all means - beta software can certainly be packaged in the AUR.  Occasionally beta software can be included in the repos too, it's just not the norm.

Last edited by Trilby (2020-12-08 20:17:40)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2020-12-08 20:23:12

Svenstaro
Administrator
From: Germany
Registered: 2008-11-19
Posts: 379

Re: building dependency from source when package exists

Yep, definitely try to make a separate package for the dependency. Also [community] has plenty of 0.x software so that aspect really won't hinder its eventual inclusion.

Offline

#4 2020-12-10 16:37:28

erbrecht
Member
From: United States
Registered: 2016-03-07
Posts: 10

Re: building dependency from source when package exists

Thanks to both of you for the feedback. I have what seems to be a working PKGBUILD, but I'm unsure about a couple things. librnnoise-ladspa is configured using a few commands, and noisetorch takes care of this. The commands, from the readme of the project, are (emphasis mine):

pacmd load-module module-null-sink sink_name=mic_denoised_out rate=48000
pacmd load-module module-ladspa-sink sink_name=mic_raw_in sink_master=mic_denoised_out label=noise_suppressor_mono plugin=/path/to/librnnoise_ladspa.so control=50
pacmd load-module module-loopback source=<your_mic_name> sink=mic_raw_in channels=1 source_dont_move=true sink_dont_move=true

So it's expecting an absolute path to the shared library. Noisetorch builds this library, then embeds the file into the executable, so it doesn't really read it from the filesystem at runtime, only on compilation, ultimately making the above commands look like (again, emphasis mine):

idx, err = c.LoadModule("module-ladspa-sink",
        fmt.Sprintf("sink_name=nui_mic_raw_in sink_master=nui_mic_denoised_out "+
            "label=noise_suppressor_mono plugin=%s control=%d", ctx.librnnoise, ctx.config.Threshold))

I basically removed the pieces of code that embed the library, and instead hard-coded the path to the shared library in the above code. I don't know if there are really any other ways to do this since that's how librnnoise works. I supposed my main question is related to that hard-coded shared library path. Is there anything wrong with doing that? Is there some other method to use during package build to get the shared library location? I know of ldconfig, but it doesn't seem like using that is appropriate in this case.

Since I had to patch a couple source files, another pair of eyes on the patches and PKGBUILD would also be much appreciated. I plan on using a very similar PKGBUILD for the new package, but grabbing the source tarball instead of pulling from git.

The new PKGBUILD:

# Maintainer alx365
# Maintainer:  Travis Collins <erbrecht at pobox dot com>
pkgname='noisetorch-git'
pkgver=0.8.2.r0.g39c1e37
pkgrel=1
pkgdesc='Real-time microphone noise suppression on Linux.'
arch=('x86_64')
url=https://github.com/lawl/NoiseTorch
license=('GPL3')
depends=('librnnoise-ladspa' 'pulseaudio' 'polkit')
makedepends=('git' 'go' 'cmake')
provides=('noisetorch')
conflicts=("noisetorch-bin")
install="${pkgname}.install"
source=('git+https://github.com/lawl/NoiseTorch.git'
        'main.patch'
        'module.patch'
        "${pkgname}.install")
sha256sums=('SKIP'
            '4a71c81fdb7dddc90cea893e4a1ff904180c6d7908ed765298549f538183d881'
            'bafd8ff2a87944bd95377bca397144c6a64755e3e1bfe4a4e9aba8fc245f898c'
            'eb72a0bb2a89deac6cb4ddb35ed9385e744e7d47a90f8ffe904673d91c6611cd')

pkgver() {
	cd NoiseTorch
	git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
	cd NoiseTorch
	#git submodule init
	#git config submodule.librnnoise_ladspa.url $srcdir/noise-suppression-for-voice
	#git submodule update
	patch -u main.go ../main.patch
	patch -u module.go ../module.patch
	export GOPATH="$srcdir/go"
	go clean -modcache
}

build() {
	cd NoiseTorch
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
	echo "go cppflags $CGO_CPPFLAGS"
	echo "go cflags   $CGO_CFLAGS"
	echo "go cxxflags $CGO_CXXFLAGS"
	echo "go ldflags  $CGO_LDFLAGS"
	echo "go flags    $GOFLAGS"
	mkdir -p bin/
	go generate
	go build -o bin/noisetorch
	go clean -modcache
}

package() {
	cd NoiseTorch
	install -D -m755 bin/noisetorch "${pkgdir}/usr/bin/noisetorch"
	sed -i 's/noisetorch.png/noisetorch/g' "assets/noisetorch.desktop"
	install -D -m644 assets/noisetorch.desktop \
		"${pkgdir}/usr/share/applications/noisetorch.desktop"
	install -D -m644 assets/icon/noisetorch.png \
		"${pkgdir}/usr/share/icons/hicolor/256x256/apps/noisetorch.png"
}

main.patch

--- main.go	2020-12-10 09:35:05.860864716 -0500
+++ main.go.1	2020-12-10 11:15:40.867108315 -0500
@@ -4,7 +4,6 @@
 	"flag"
 	"fmt"
 	"image"
-	"io/ioutil"
 	"log"
 	"os"
 	"path/filepath"
@@ -19,7 +18,6 @@
 	"github.com/aarzilli/nucular/style"
 )
 
-//go:generate go run scripts/embedlibrnnoise.go
 //go:generate go run scripts/embedversion.go
 //go:generate go run scripts/embedlicenses.go
 
@@ -85,12 +83,9 @@
 	log.Printf("CAP_SYS_RESOURCE: %t\n", hasCapSysResource(getCurrentCaps()))
 
 	initializeConfigIfNot()
-	rnnoisefile := dumpLib()
-	defer removeLib(rnnoisefile)
 
 	ctx := ntcontext{}
 	ctx.config = readConfig()
-	ctx.librnnoise = rnnoisefile
 
 	paClient, err := pulseaudio.NewClient()
 
@@ -168,24 +163,6 @@
 
 }
 
-func dumpLib() string {
-	f, err := ioutil.TempFile("", "librnnoise-*.so")
-	if err != nil {
-		log.Fatalf("Couldn't open temp file for librnnoise\n")
-	}
-	f.Write(libRNNoise)
-	log.Printf("Wrote temp librnnoise to: %s\n", f.Name())
-	return f.Name()
-}
-
-func removeLib(file string) {
-	err := os.Remove(file)
-	if err != nil {
-		log.Printf("Couldn't delete temp librnnoise: %v\n", err)
-	}
-	log.Printf("Deleted temp librnnoise: %s\n", file)
-}
-
 func getSources(client *pulseaudio.Client) []input {
 	sources, err := client.Sources()
 	if err != nil {

module.patch

--- module.go	2020-12-10 09:35:05.860864716 -0500
+++ module.go.1	2020-12-10 10:46:53.979280435 -0500
@@ -104,7 +104,7 @@
 
 	idx, err = c.LoadModule("module-ladspa-sink",
 		fmt.Sprintf("sink_name=nui_mic_raw_in sink_master=nui_mic_denoised_out "+
-			"label=noise_suppressor_mono plugin=%s control=%d", ctx.librnnoise, ctx.config.Threshold))
+			"label=noise_suppressor_mono plugin=%s control=%d", "/usr/lib/librnnoise_ladspa.so", ctx.config.Threshold))
 	if err != nil {
 		return err
 	}

Offline

#5 2020-12-10 21:00:34

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,876

Re: building dependency from source when package exists

That seems mostly sane. big_smile

Note: https://www.freedesktop.org/wiki/Softwa … adspa-sink

It should be "plugin=librnnoise_ladspa.so" and the plugin should be installed to /usr/lib/ladspa/


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#6 2020-12-11 14:24:53

erbrecht
Member
From: United States
Registered: 2016-03-07
Posts: 10

Re: building dependency from source when package exists

Oh, very nice catch. I probably should have looked for documentation on that.

Actually, the AUR package I was including as a dependency no longer exists. There is another one called noise-suppression-for-voice based on the same repo/source code. It puts the share library in the expected location under /usr/lib/ladspa, so I think I'm all set after updating that particular patch.

Thanks again for all the help.

Offline

#7 2020-12-11 14:37:26

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,876

Re: building dependency from source when package exists


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB