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

Not available on freebsd - because of sysinfo? #8

Open
scoobybejesus opened this issue Jan 14, 2025 · 14 comments
Open

Not available on freebsd - because of sysinfo? #8

scoobybejesus opened this issue Jan 14, 2025 · 14 comments

Comments

@scoobybejesus
Copy link

Hi there,

FreeBSD has a sysinfo package, as well as a libsysinfo package.

$ pkg search sysinfo
libsysinfo-0.0.3_3             GNU libc's sysinfo port for FreeBSD
{...}
sysinfo-1.0.1_3                Utility used to gather system configuration information

It may not be too difficult to add FreeBSD support.

It seems liquidsoap 2.3.x can't be built on FreeBSD because of this:

#=== ERROR while compiling liquidsoap-core.2.3.0 ==============================#
# context     2.3.0 | freebsd/x86_64 | ocaml-base-compiler.4.14.2 | https://opam.ocaml.org#26328df81683ba1e6ceab0ca32fa3c2cc2ead1c1
# path        /usr/home/radio/.opam/4.14.2/.opam-switch/build/liquidsoap-core.2.3.0
# command     /usr/home/radio/.opam/4.14.2/bin/dune build -p liquidsoap-core -j 3 --promote-install-files=false @install
# exit-code   1
# env-file    /usr/home/radio/.opam/log/liquidsoap-core-98379-eb78c8.env
# output-file /usr/home/radio/.opam/log/liquidsoap-core-98379-eb78c8.out
### output ###
# File "src/bin/dune", line 2, characters 7-17:
# 2 |  (name liquidsoap)
#            ^^^^^^^^^^
# (cd _build/default && /usr/home/radio/.opam/4.14.2/bin/ocamlopt.opt -w -40 -g -o src/bin/liquidsoap.exe -linkall /usr/home/radio/.opam/4.14.2/lib/ocaml/unix.cmxa -I /usr/home/radio/.opam/4.14.2/lib/ocaml /usr/home/radio/.opam/4.14.2/lib/mm/base/mm_base.cmxa /usr/home/radio/.opam/4.14.2/lib/mm/audio/mm_audio.cmxa -I /usr/home/radio/.opam/4.14.2/lib/mm/audio /usr/home/radio/.opam/4.14.2/lib/mm/[...]
# ld: error: undefined symbol: sysinfo
# >>> referenced by mem_usage.c:219
# >>>               mem_usage.o:(ocaml_mem_usage_mem_usage) in archive /usr/home/radio/.opam/4.14.2/lib/mem_usage/libmem_usage_stubs.a
# cc: error: linker command failed with exit code 1 (use -v to see invocation)
# File "caml_startup", line 1:
# Error: Error during linking (exit code 1)

Do you have any notes on what didn't work for FreeBSD? Perhaps an intrepid contributor could add support. Would you be alright with that?

@toots
Copy link
Member

toots commented Jan 14, 2025

Hi!

I'd be super down to add support for freebsd if anyone can contribute it!

@toots
Copy link
Member

toots commented Jan 14, 2025

We could also make mem_usage optional for liquidsoap. I'll consider that for the next rolling release.

@scoobybejesus
Copy link
Author

After searching and searching, I found something to try that worked!

What I was previously doing

C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include \
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:usr/local/include \
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib \
opam install lame cry samplerate ffmpeg liquidsoap

What worked:

C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include \
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:usr/local/include \
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib \
CFLAGS='-I/usr/local/include -Wno-zero-length-array' \
LDFLAGS='-L/usr/local/lib -lsysinfo' \
opam install lame cry samplerate ffmpeg liquidsoap

In particular, I had to include:

CFLAGS='-I/usr/local/include -Wno-zero-length-array' LDFLAGS='-L/usr/local/lib -lsysinfo' 

In total:

$ C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:usr/local/include LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib CFLAGS='-I/usr/local/include -Wno-zero-length-array' LDFLAGS='-L/usr/local/lib -lsysinfo' opam install lame cry samplerate ffmpeg liquidsoap
[NOTE] Package ffmpeg is already installed (current version is 1.2.1).
[NOTE] Package samplerate is already installed (current version is 0.1.6).
[NOTE] Package cry is already installed (current version is 1.0.3).
[NOTE] Package lame is already installed (current version is 0.3.7).
The following actions will be performed:
=== install 2 packages
  ∗ liquidsoap      2.3.0
  ∗ liquidsoap-core 2.3.0 [required by liquidsoap]

Proceed with ∗ 2 installations? [y/n] y

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved liquidsoap.2.3.0, liquidsoap-core.2.3.0  (cached)
∗ installed liquidsoap-core.2.3.0
∗ installed liquidsoap.2.3.0
Done.

<><> liquidsoap.2.3.0 installed successfully ><><><><><><><><><><><><><><><><><>
=> ✨ Congratulations on installing liquidsoap! ✨
=> We noticed that you did not install any ssl or tls support. Liquidsoap won't
   be able to use SSL encryption in its input or output operators. You might want
   to install one of ssl or tls-liquidsoap package.

I don't know how to adjust any build script stuff accordingly, if that would do it, but this recipe in total does seem to do the trick. I'm up and running. So far so good.

@toots
Copy link
Member

toots commented Jan 14, 2025

You were able to build mem_usage too?

@toots
Copy link
Member

toots commented Jan 14, 2025

ho I see.

@toots
Copy link
Member

toots commented Jan 14, 2025

@scoobybejesus can you provide the output of ocamlc -config on freebsd?

@scoobybejesus
Copy link
Author

$ ocamlc -config
version: 4.14.2
standard_library_default: /usr/home/radio/.opam/4.14.2/lib/ocaml
standard_library: /usr/home/radio/.opam/4.14.2/lib/ocaml
ccomp_type: cc
c_compiler: cc
ocamlc_cflags: -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC
ocamlc_cppflags: -D_FILE_OFFSET_BITS=64
ocamlopt_cflags: -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC
ocamlopt_cppflags: -D_FILE_OFFSET_BITS=64
bytecomp_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64
native_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64
bytecomp_c_libraries: -lm  -lpthread
native_c_libraries: -lm
native_pack_linker: ld -r -o
architecture: amd64
model: default
int_size: 63
word_size: 64
system: freebsd
asm: cc -c
asm_cfi_supported: true
with_frame_pointers: false
ext_exe:
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
host: x86_64-unknown-freebsd14.0
target: x86_64-unknown-freebsd14.0
flambda: false
safe_string: true
default_safe_string: true
flat_float_array: true
function_sections: true
afl_instrument: false
windows_unicode: false
supports_shared_libraries: true
naked_pointers: true
exec_magic_number: Caml1999X031
cmi_magic_number: Caml1999I031
cmo_magic_number: Caml1999O031
cma_magic_number: Caml1999A031
cmx_magic_number: Caml1999Y031
cmxa_magic_number: Caml1999Z031
ast_impl_magic_number: Caml1999M031
ast_intf_magic_number: Caml1999N031
cmxs_magic_number: Caml1999D031
cmt_magic_number: Caml1999T031
linear_magic_number: Caml1999L031

@scoobybejesus
Copy link
Author

I had been fighting this for a few hours. I'm not sure if I only was able to get mem_usage installed was because I cloned the repo and ran opam install -y . in the repo directory. But that installed without issue after installing the sysinfo packages (I'm not sure which at this point). I could test later to confirm.

@toots
Copy link
Member

toots commented Jan 14, 2025

Great thanks. Can you try to installed a pinned version from the latest main branch and see if you still need those options to build afterward?

@scoobybejesus
Copy link
Author

scoobybejesus commented Jan 18, 2025

Sorry for the delay.

First, I tried a new jail, attempting everything through opam, just to eliminate variables.

$ ocamlc -config
version: 5.2.1
standard_library_default: /usr/home/radio/.opam/default/lib/ocaml
standard_library: /usr/home/radio/.opam/default/lib/ocaml
ccomp_type: cc
c_compiler: cc
ocamlc_cflags:  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread
ocamlc_cppflags:  -D_FILE_OFFSET_BITS=64
ocamlopt_cflags:  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread
ocamlopt_cppflags:  -D_FILE_OFFSET_BITS=64
bytecomp_c_compiler: cc  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread  -D_FILE_OFFSET_BITS=64
native_c_compiler: cc  -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -pthread  -D_FILE_OFFSET_BITS=64
bytecomp_c_libraries: -lzstd  -lm  -lpthread
native_c_libraries:  -lm  -lpthread
native_ldflags:
native_pack_linker: ld -r -o
native_compiler: true
architecture: amd64
model: default
int_size: 63
word_size: 64
system: freebsd
asm: cc -c
asm_cfi_supported: true
with_frame_pointers: false
ext_exe:
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
host: x86_64-unknown-freebsd14.2
target: x86_64-unknown-freebsd14.2
flambda: false
safe_string: true
default_safe_string: true
flat_float_array: true
function_sections: true
afl_instrument: false
tsan: false
windows_unicode: false
supports_shared_libraries: true
native_dynlink: true
naked_pointers: false
exec_magic_number: Caml1999X034
cmi_magic_number: Caml1999I034
cmo_magic_number: Caml1999O034
cma_magic_number: Caml1999A034
cmx_magic_number: Caml1999Y034
cmxa_magic_number: Caml1999Z034
ast_impl_magic_number: Caml1999M034
ast_intf_magic_number: Caml1999N034
cmxs_magic_number: Caml1999D034
cmt_magic_number: Caml1999T034
linear_magic_number: Caml1999L034

I include mad, and I had to clone the opam repository and make a modification to get it to cooperate:

diff --git a/packages/conf-mad/conf-mad.1/opam b/packages/conf-mad/conf-mad.1/opam
index 2d18625287..a6ebcd4ddd 100644
--- a/packages/conf-mad/conf-mad.1/opam
+++ b/packages/conf-mad/conf-mad.1/opam
@@ -6,7 +6,7 @@ authors: "mad dev team"
 license: "GPL-2.0-only"
 build: [
   ["pkg-config" "--exists" "mad"] {os != "freebsd"}
-  ["pkg-config" "--exists" "libmad"] {os = "freebsd"}
+  ["pkg-config" "--exists" "mad"] {os = "freebsd"}
 ]
 depends: [
   "conf-pkg-config" {build}

But I had to have the full command to install using opam (including the requisite libs, notably just libsysinfo not sysinfo)

$ pkg install -y git icecast mime-support py311-virtualenv libogg nginx ffmpeg gmake bash sqlite3 py311-sqlite3
$ pkg install -y ocaml-opam libmad libsamplerate pkgconf gavl fdk-aac pcre libsysinfo
$ opam init (which built 5.3.0, but which was reverted to 5.2.1 in the subsequent command)
$ C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include \
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:usr/local/include \
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib \
CFLAGS='-I/usr/local/include -Wno-zero-length-array' \
LDFLAGS='-L/usr/local/lib -lsysinfo' \
opam install fdkaac gavl mad lame vorbis cry samplerate ffmpeg liquidsoap

Now we'll do a new try from scratch again, this time using the main branch. Also, pcre is deprecated in favor of pcre2 so I did that, and I'm using sysinfo instead of libsysinfo. I may want to do another run like this with libsysinfo.

Again, it built 5.3.0 on opam init. I had pkg installed the libs and such I thought I needed, so I moved on.

I cloned the liquidsoap repo, and ran opam init -y .. It complained I needed to pkg install ca_root_nss sdl2 sdl2_image sdl2_ttf so I did that and tried again. It looks like everything worked except mem_usage.

#=== ERROR while compiling mem_usage.0.1.1 ====================================#
# context     2.3.0 | freebsd/x86_64 | ocaml.5.3.0 | https://opam.ocaml.org#da383c8610c72e3b8a92e6327148910d1d81cd57
# path        /usr/home/radio/.opam/default/.opam-switch/build/mem_usage.0.1.1
# command     /usr/home/radio/.opam/default/bin/dune build -p mem_usage -j 3 @install
# exit-code   1
# env-file    /usr/home/radio/.opam/log/mem_usage-75885-6cb33f.env
# output-file /usr/home/radio/.opam/log/mem_usage-75885-6cb33f.out
### output ###
# File "lib/dune", line 7, characters 9-18:
# 7 |   (names mem_usage))
#              ^^^^^^^^^
# (cd _build/default/lib && /usr/bin/cc -O2 -fno-strict-aliasing -fwrapv -fPIC -pthread -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -fPIC -pthread -g -I /usr/home/radio/.opam/default/lib/ocaml -o mem_usage.o -c mem_usage.c)
# mem_usage.c:204:10: fatal error: 'sys/sysinfo.h' file not found
#   204 | #include <sys/sysinfo.h>
#       |          ^~~~~~~~~~~~~~~
# 1 error generated.

And I started tacking on those env adjustments, and it would never build, so I got rid of sysinfo and put libsysinfo back, and I repeated the same thing... and got the same result. And then put back sysinfo, so now I have both again, and again same result.

So then I was looking back, and I had been successful with 4.14.2 compiler, so I ran opam switch create 4.14.2. Once again:

C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include \
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:usr/local/include \
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib \
CFLAGS='-I/usr/local/include -Wno-zero-length-array' \
LDFLAGS='-L/usr/local/lib -lsysinfo' \
opam install lame cry samplerate ffmpeg .

And to my surprise it worked!

<><> liquidsoap-mode.2.3.1 installed successfully <><><><><><><><><><><><><><><>
=> This package requires additional configuration for use in editors. Install package 'user-setup', or manually:

   * for Emacs, add these lines to ~/.emacs:
     (add-to-list 'load-path "/usr/home/radio/.opam/4.14.2/share/emacs/site-lisp")
     (require 'emacs-mode)

<><> liquidsoap.2.3.1 installed successfully ><><><><><><><><><><><><><><><><><>
=> ✨ Congratulations on installing liquidsoap! ✨

This was the ocamlc config:

$ ocamlc -config
version: 4.14.2
standard_library_default: /usr/home/radio/.opam/4.14.2/lib/ocaml
standard_library: /usr/home/radio/.opam/4.14.2/lib/ocaml
ccomp_type: cc
c_compiler: cc
ocamlc_cflags: -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC
ocamlc_cppflags: -D_FILE_OFFSET_BITS=64
ocamlopt_cflags: -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC
ocamlopt_cppflags: -D_FILE_OFFSET_BITS=64
bytecomp_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64
native_c_compiler: cc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64
bytecomp_c_libraries: -lm  -lpthread
native_c_libraries: -lm
native_pack_linker: ld -r -o
architecture: amd64
model: default
int_size: 63
word_size: 64
system: freebsd
asm: cc -c
asm_cfi_supported: true
with_frame_pointers: false
ext_exe:
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
host: x86_64-unknown-freebsd14.2
target: x86_64-unknown-freebsd14.2
flambda: false
safe_string: true
default_safe_string: true
flat_float_array: true
function_sections: true
afl_instrument: false
windows_unicode: false
supports_shared_libraries: true
naked_pointers: true
exec_magic_number: Caml1999X031
cmi_magic_number: Caml1999I031
cmo_magic_number: Caml1999O031
cma_magic_number: Caml1999A031
cmx_magic_number: Caml1999Y031
cmxa_magic_number: Caml1999Z031
ast_impl_magic_number: Caml1999M031
ast_intf_magic_number: Caml1999N031
cmxs_magic_number: Caml1999D031
cmt_magic_number: Caml1999T031
linear_magic_number: Caml1999L031

So now I guess I need to do this exercise again, trying with the 4.14.2 compiler, and starting again with cloning the liquidsoap repo and a plain opam install -y . But this comment is huge, so I'll stop for now.

@toots
Copy link
Member

toots commented Jan 18, 2025

Fix to conf-mad submitted: ocaml/opam-repository#27290

As for mem_usage, I have added the required flags in the latest git repo: fc7e357

So I wanted to know if the package was working when you pinned it. If so, we could publish a new release and everything would work I believe.

To pin in:

git clone https://github.com/savonet/ocaml-mem_usage.git
cd ocaml-mem_usage
opam pin -n .

Then you can continue your install as expected and should not have to set those LDFLAGS.

@scoobybejesus
Copy link
Author

Ah, that's what you meant. Shoot. You wanted me to pin the main of this repo, not of liquidsoap. 🙈

Yes, the opam install incantation no longer needs to include CFLAGS='-I/usr/local/include -Wno-zero-length-array' LDFLAGS='-L/usr/local/lib -lsysinfo' to build/install.

@toots
Copy link
Member

toots commented Jan 19, 2025

Great! Releasing a new version right now!

@toots
Copy link
Member

toots commented Jan 19, 2025

Here we go: ocaml/opam-repository#27291

Thanks again!

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

No branches or pull requests

2 participants