Skip to content

Conversation

@eli-schwartz
Copy link
Contributor

The meson build system has builtin support for python packaging, and unlike hatchling it is spec-compliant. Additionally, meson is already responsible for building the shared library itself, which the python build backend can then distribute inside the wheel. This allows shipping a wheel that can find its own liblc3.so via ctypes and doesn't require passing paths to the library around, nor to install both separately and hope that this works.

@eli-schwartz
Copy link
Contributor Author

@asoulier by the way, python packaging is another thing you can ask me about. ;)

@asoulier
Copy link
Collaborator

Thank Eli. That works great ;)
Can you just update the README.md with pip inistall . instead of python3 -m pip install ./python.
Thanks.

Can I also ask you for some help with building WASM with meson?
@DeltaEvo is working on a port to WASM, without relying on emscripten.
We have modified the Makefile (not committed for now) to use clang with the wasm32 target.
That works fine; I wanted to know if there is a possibility with meson to compile the wasm32 target, too (I actually only see the emscripten option).

@DeltaEvo
Copy link
Contributor

DeltaEvo commented Feb 26, 2024

We have modified the Makefile (not committed for now)

It is committed e67bb2d

@eli-schwartz
Copy link
Contributor Author

I know little to nothing about wasm. I tried writing a simple meson cross toolchain file:

[binaries]
c = ['clang', '--target=wasm32']

[built-in options]
c_args = ['-mbulk-memory']
c_link_args = ['-nostdlib', '-Wl,--no-entry', '-Wl,--export-dynamic']
b_asneeded = false
b_lundef = false

configure log:

Build type: cross build
Project name: lc3
Project version: 1.0.4
C compiler for the host machine: clang --target=wasm32 (clang 17.0.6 "clang version 17.0.6")
C linker for the host machine: clang --target=wasm32 ld.lld 17.0.6
C compiler for the build machine: ccache cc (gcc 13.2.1 "cc (Gentoo 13.2.1_p20240113-r1 p12) 13.2.1 20240113")
C linker for the build machine: cc ld.bfd 2.41
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
Library m found: NO
Found pkg-config: NO
Build targets in project: 1

lc3 1.0.4

  User defined options
    Cross files: ../cr.ini

Found ninja-1.11.1 at /usr/bin/ninja
WARNING: Cross file does not specify strip binary, result will not be stripped.
WARNING: Cross file does not specify strip binary, result will not be stripped.

compile log:

ninja: Entering directory `builddir/'
[13/13] Linking target src/liblc3.so.1
FAILED: src/liblc3.so.1 
clang --target=wasm32  -o src/liblc3.so.1 src/liblc3.so.1.p/attdet.c.o src/liblc3.so.1.p/bits.c.o src/liblc3.so.1.p/bwdet.c.o src/liblc3.so.1.p/energy.c.o src/liblc3.so.1.p/lc3.c.o src/liblc3.so.1.p/ltpf.c.o src/liblc3.so.1.p/mdct.c.o src/liblc3.so.1.p/plc.c.o src/liblc3.so.1.p/sns.c.o src/liblc3.so.1.p/spec.c.o src/liblc3.so.1.p/tables.c.o src/liblc3.so.1.p/tns.c.o -flto -shared -fPIC -Wl,--start-group -Wl,-soname,liblc3.so.1 -Wl,--end-group -nostdlib -Wl,--no-entry -Wl,--export-dynamic
wasm-ld: error: unknown argument: --start-group
wasm-ld: error: unknown argument: -soname
wasm-ld: error: unknown argument: --end-group
wasm-ld: error: cannot open liblc3.so.1: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

So close, yet so far. It seems like meson may need a small tweak or so to get this to work.

@eli-schwartz
Copy link
Contributor Author

The start-group end-group stuff is technically used in the event that a library has multiple dependencies which liblc3 doesn't have, so my meson PR should count as a perfectly adequate workaround.

Configuring with -Ddefault_library=static tells meson to only build a wasm library for src/liblc3.a, not a shared library, which may or may not be suitable.

The meson build system has builtin support for python packaging, and
unlike hatchling it is spec-compliant. Additionally, meson is already
responsible for building the shared library itself, which the python
build backend can then distribute inside the wheel. This allows shipping
a wheel that can find its own liblc3.so via ctypes and doesn't require
passing paths to the library around, nor to install both separately and
hope that this works.
@eli-schwartz
Copy link
Contributor Author

README updated. PTAL.

@asoulier asoulier merged commit 3f05fcb into google:main Feb 27, 2024
@eli-schwartz eli-schwartz deleted the meson-python branch February 28, 2024 00:54
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.

3 participants