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

FreeBSD build fails Error: No statfs implementation #262

Closed
dch opened this issue Mar 31, 2021 · 10 comments
Closed

FreeBSD build fails Error: No statfs implementation #262

dch opened this issue Mar 31, 2021 · 10 comments

Comments

@dch
Copy link

dch commented Mar 31, 2021

I've found a couple of failures while building on FreeBSD - if these can be fixed I can add avalanchemq to FreeBSD ports/packages. I will report it in crystal repo & link back to here.

> shards version
1.0.0-alpha.27

> crystal version
Crystal 0.36.1 ()

LLVM: 10.0.1
Default target: x86_64-portbld-freebsd13.0

> uname -a
FreeBSD wintermute 13.0-RC4 FreeBSD ... amd64

> gsh
commit a8c83ffc5d458d672758be35ec78a4752151332c (HEAD -> main, origin/main, origin/HEAD)

> shards build --release --production
Resolving dependencies
Fetching https://github.com/cloudamqp/amq-protocol.cr.git
Fetching https://github.com/tbrand/router.cr.git
Fetching https://github.com/luislavena/radix.git
Fetching https://github.com/schovi/baked_file_system.git
Fetching https://github.com/cloudamqp/amqp-client.cr.git
Fetching https://github.com/84codes/http-protection.git
Fetching https://github.com/84codes/systemd.cr.git
Fetching https://github.com/crystal-lang/logger.cr.git
Using radix (0.4.0)
Using router (0.2.7)
Installing baked_file_system (0.9.8 at fd6ba88)
Installing amq-protocol (1.0.0)
Installing amqp-client (1.0.0)
Installing http-protection (0.2.0 at 893a191)
Using systemd (1.1.2)
Installing logger (0.1.0)
Building: avalanchemq
Error target avalanchemq failed to compile:
Showing last frame. Use --error-trace for full trace.

In src/avalanchemq.cr:2:1

 2 | require "./stdlib/*"
     ^
Error: No statfs implementation

FreeBSD's statfs(2) is simlar to Darwin:

      *	filesystem statistics
      */

     #define MFSNAMELEN	     16		     /*	length of type name including null */
     #define MNAMELEN	     1024	     /*	size of	on/from	name bufs */
     #define STATFS_VERSION  0x20140518	     /*	current	version	number */

     struct statfs {
     uint32_t f_version;	     /*	structure version number */
     uint32_t f_type;		     /*	type of	filesystem */
     uint64_t f_flags;		     /*	copy of	mount exported flags */
     uint64_t f_bsize;		     /*	filesystem fragment size */
     uint64_t f_iosize;		     /*	optimal	transfer block size */
     uint64_t f_blocks;		     /*	total data blocks in filesystem	*/
     uint64_t f_bfree;		     /*	free blocks in filesystem */
     int64_t  f_bavail;		     /*	free blocks avail to non-superuser */
     uint64_t f_files;		     /*	total file nodes in filesystem */
     int64_t  f_ffree;		     /*	free nodes avail to non-superuser */
     uint64_t f_syncwrites;	     /*	count of sync writes since mount */
     uint64_t f_asyncwrites;	     /*	count of async writes since mount */
     uint64_t f_syncreads;	     /*	count of sync reads since mount	*/
     uint64_t f_asyncreads;	     /*	count of async reads since mount */
     uint64_t f_spare[10];	     /*	unused spare */
     uint32_t f_namemax;	     /*	maximum	filename length	*/
     uid_t     f_owner;		     /*	user that mounted the filesystem */
     fsid_t    f_fsid;		     /*	filesystem id */
     char      f_charspare[80];		 /* spare string space */
     char      f_fstypename[MFSNAMELEN]; /* filesystem type name */
     char      f_mntfromname[MNAMELEN];	 /* mounted filesystem */
     char      f_mntonname[MNAMELEN];	 /* directory on which mounted */
     };

A partial patch for src/stdlib/filesystem.cr looks like this, but I have no idea yet how the fields (with C comments still) map to crystal syntax/structures:

  {% elsif flag?(:freebsd) %}
    struct Statfs
     #define STATFS_VERSION  0x20140518	     /*	current	version	number */
      version : UInt32
      type : UInt32
      flags : UInt64
      bsize : UInt64
      iosize : UInt64
      blocks : UInt64
      bfree : UInt64
      bavail : Int64
      files : UInt64
      ffree : Int64
      ffree : UInt64
      syncwrites : UInt64
      asyncwrites : UInt64
      syncreads : UInt64
      asyncreads : UInt64
     uint64_t f_spare[10];	     /*	unused spare */
      namemax : UInet32
     uid_t     f_owner;		     /*	user that mounted the filesystem */
     fsid_t    f_fsid;		     /*	filesystem id */
     char      f_charspare[80];		 /* spare string space */
     char      f_fstypename[MFSNAMELEN]; /* filesystem type name */
     char      f_mntfromname[MNAMELEN];	 /* mounted filesystem */
     char      f_mntonname[MNAMELEN];	 /* directory on which mounted */
    end

There's a similar error for getrlimit getrlimit(2)

Error target avalanchemq failed to compile:
Showing last frame. Use --error-trace for full trace.

In src/stdlib/resource.cr:21:22

 21 | fun getrlimit(Int, Rlimit*) : Int
                         ^-----
Error: undefined constant Rlimit

which appears to be https://cgit.freebsd.org/src/tree/sys/sys/resource.h#n112

#define	RLIMIT_NOFILE	8		/* number of open files */
#define	RLIMIT_SBSIZE	9		/* maximum size of all socket buffers */

I'd be happy to collaborate on this if you're willing to help out with the crystal syntax etc.

@carlhoerberg
Copy link
Member

Ok, thank you for your findings!

Made PR to crystal for RLimit: crystal-lang/crystal#10569

But also monkey patched here: 6560de7

And added Statfs for bsd platforms too:
d47e2e2

@carlhoerberg
Copy link
Member

Would be awesome to see a GH action that built avalanchemq in freebsd, maybe with https://github.com/vmactions/freebsd-vm ?

@dch
Copy link
Author

dch commented Apr 1, 2021

image

Thanks! I will look into that, although perhaps using qemu/ubuntu instead of ... macos .. as a target!

In the interim, if you're willing to add a github post-commit webhook, I can at least build it locally here each time.

@dentarg
Copy link
Member

dentarg commented Apr 1, 2021

Thanks! I will look into that, although perhaps using qemu/ubuntu instead of ... macos .. as a target!

The reason for it using macOS, I believe, is that GitHub Actions doesn't allow nested virtualization for the Azure VMs: actions/runner-images#183

@dentarg
Copy link
Member

dentarg commented Apr 1, 2021

There are other CI solutions we could use, e.g. https://cirrus-ci.org/features/ which have FreeBSD

@dch
Copy link
Author

dch commented Apr 1, 2021

> shards build --release --production
Dependencies are satisfied
Building: avalanchemq
Error target avalanchemq failed to compile:
ld: error: undefined symbol: statfs64
>>> referenced by filesystem.cr:61 (/repos/avalanchemq/src/stdlib/filesystem.cr:61)
>>>               _main.o:(~procProc(Nil)@src/avalanchemq/server.cr:46)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
Error: execution of command failed with code: 1: `cc "${@}" -o /repos/avalanchemq/bin/avalanchemq  -rdynamic -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre -lm -lgc-threaded -lpthread /usr/local/lib/crystal/ext/libcrystal.a -L/usr/local/lib -levent  -lpthread`

I'm not really clear what the issue here is - I'll take a closer look next week once I have some more familiarity with crystal under my belt. But I guess the monkey-patching isn't sufficient -- the Darwin & FreeBSD structs are not so similar.

@carlhoerberg
Copy link
Member

THank you for the tip @dentarg , set up cirrus: https://cirrus-ci.com/github/cloudamqp/avalanchemq

@carlhoerberg
Copy link
Member

Got it working, but now there's some OpenSSL issue with crystal in freebsd: https://cirrus-ci.com/task/6046301113548800
Should probably be raised with crystal-lang. Also notice that crystal 0.36.1 is installed on freebsd rather than 1.0.0, maybe it's an issue solved since 0.36.1 🤷

@dch
Copy link
Author

dch commented Apr 1, 2021

yeah we should bump that. you'll need pkg install -r FreeBSD security/openssl for the above issue, I think. Or crystal is not looking in /usr/lib for its crypto goodies. thanks!

@carlhoerberg
Copy link
Member

Ah, cool, thanks! It's progressing! https://cirrus-ci.com/task/5046482723143680

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

3 participants