Code Monkey home page Code Monkey logo

librarycheck's Introduction

LibraryCheck

Determine whether a shared library is available to be loaded by Raku

Build Status

Synopsis

use LibraryCheck;

if !library-exists('sndfile', v1) {
    die "Cannot load libsndfile";
}

Description

This module provides a mechanism that will determine whether a named shared library is available and can be used by NativeCall.

It exports a single function library-exists that returns a boolean to indicate whether the named shared library can be loaded and used. The library name should be supplied without any (OS-dependent) "lib" prefix and no extension (for example, 'crypt' for libcrypt.so).

This can be used in a builder to determine whether a module has a chance of working (and possibly aborting the build), or in tests to cause the tests that may rely on a missing library to be skipped.

The second positional argument is a Version object that indicates the version of the library that is required, it defaults to v1, if you don't care which version exists then it possible to pass a new Version object without any version parts (i.e., Version.new()). Many systems require that the version is specified, so if portability is a concern, an actual version number should be given.

If the :exception adverb is passed to library-exists then an exception (X::NoLibrary) will be thrown if the library isn't available rather than returning False. So the case above can be more simply written as:

library-check('sndfile', v1, :exception);

The implementation is somewhat of a hack currently and definitely shouldn't be taken as an example of nice Raku code.

Installation

Assuming you have a working Rakudo installation you should be able to install this with zef:

# From the source directory

zef install .

# Remote installation

zef install LibraryCheck

Other install mechanisms may be become available in the future.

Support

Suggestions/patches are welcomed via github at https://github.com/jonathanstowe/LibraryCheck/issues

I'd be particularly interested in having it work properly on all the platforms that rakudo will work on.

Licence

Please see the LICENCE file in the distribution.

© Jonathan Stowe 2015 - 2021

librarycheck's People

Contributors

cono avatar jonathanstowe avatar softmoth avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

librarycheck's Issues

Tests failing against Rakudo HEAD

Encountered today using Rakudo HEAD (rakudo/rakudo@7e7aa26): The bogus library checks don't throw or error out as intended,

===> Testing: LibraryCheck:ver<0.0.8>:auth<github:jonathanstowe>:api<1.0>
[LibraryCheck] # Failed test 'not ok for a bogus one'
[LibraryCheck] # at t/010-basic.t line 11
[LibraryCheck]     # Failed test 'code dies'
[LibraryCheck]     # at t/010-basic.t line 14
[LibraryCheck]     # You failed 1 test of 2
[LibraryCheck] # Failed test 'bogus one throws X::NoLibrary with :exception'
[LibraryCheck] # at t/010-basic.t line 14
[LibraryCheck] # You failed 2 tests of 4
===> Testing [FAIL]: LibraryCheck:ver<0.0.8>:auth<github:jonathanstowe>:api<1.0>

Reproduced on macOS and OpenBSD.

:auto-die

That would be great if it accepts a auto-die adverb, that would throw a exception when couldn't load the library... Maybe accept the exception class as parameter

Thanks

Unexplained memory leak...

Somehow, the library-check routine leaks memory....and lots of it.

Tested on both Linux and FreeBSD.

+++++++++++++++++++++++++++++++++++++++++
use LibraryCheck;

sub MAIN()
{
my Int $counter = 0;
loop {
if library-exists('libncurses.so') {
say "libncurses.so";
}
sleep(1) if ++$counter % 1000 == 0;
}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.