Giter VIP home page Giter VIP logo

hlibsass's Introduction

hLibsass

Linux Build Status Windows Build Status Hackage Hackage deps

hLibsass is a low-level binding to LibSass. It provides basic types used by the library along with a FFI interface to the C API.

This is really a low-level library, if you want a high-level, more Haskell-friendly library, check out hSass.

It is available on Hackage.

hLibsass' Changelog

A note from maintainer

Although it might seem like this package is dead - it is not. I am maintaining it (willing to maintain), it's just that I don't use it anymore and can't really detect bugs proactively. This also applies to LibSass updates - I am not monitoring it. If you want a bug fixed or LibSass version bumped, just open an issue and I will try to solve it! :)

Documentation

This library is (mostly) 1-1 binding to LibSass. See LibSass wiki for documentation.

Static, shared or external version of LibSass?

hLibsass supports three different ways of linking with Libsass:

  1. Static, locally-built LibSass,
  2. Shared, locally-built LibSass, requires setting sharedLibsass flag,
  3. External (e.g. system package), requires setting externalLibsass flag.

The first two options rely on the LibSass being distributed with the hlibsass package and compiled during configure/build process. hLibsass is always distributed with LibSass version that is compatibile with the package.

Up until version 0.1.6.0, the first option was preferred, because LibSass has been distributed as a source package only. Development package of LibSass is now available in most Linux distributions and in Homebrew, so using it is equally good option

Using locally-built shared version of LibSass may require adjusting LD_LIBRARY_PATH or putting libsass.so somewhere in the PATH, so this option is discouraged. However, if you really want to use it that way, you may use tools/libpath.sh to set LD_LIBRARY_PATH (it extracts the library location using ghc-pkg).

externalLibsass flag has precedence over sharedLibsass.

hLibsass and LibSass version

hLibsass uses LibSass internally and therefore is quite tightly bound to LibSass. Every breaking change in LibSass C API will break hLibSass (either at compile-time or at runtime, depends on the change). For now, these combinations should work:

  • hLibsass 0.1.5.x with LibSass 3.3.2 (distributed with) and 3.4.3 (not every function is reexported, but there were no changes that would break hLibSass),
  • hLibsass 0.1.6.x with LibSass 3.4.3 (distributed with),
  • hLibsass 0.1.7.x with LibSass 3.5.2 (distributed with)
  • hLibsass 0.1.8.x with LibSass 3.5.5 (distributed with),
  • hLibsass 0.1.9.x with LibSass 3.6.3 (distributed with),
  • hLibsass 0.1.10.x with LibSass 3.6.4 (distributed with),
  • LibSass 3.5.x WILL have breaking changes and will result in runtime failures of hLibSass versions prior to 0.1.7.0 (and probably compile-time failures too), see LibSass releases page for more details.

Building on Windows

hLibsass by default builds LibSass as part of it's build process. This means that it will require C & C++ compiler. On Linux that is not a problem most of the time since Clang/GCC is (almost) available on bare systems. On Windows it requires a little bit of additional packages.

The minimum that hLibsass requires is MinGW-w64. Installing it and compilig hLibsass using it's shell (so that PATH is configured correctly) should be enough to get started.

Up until hLibsass 0.1.10, hLibsass required also env binary. It is distributed as part of Cygwin/MSYS2. The easiest way to use that is to use Stack. It installs MSYS2 as part of their setup and compiles your packages inside POSIX-compatibile shell. You can follow instructrions on Stack documentation on how to install MinGW-w64 there.

Things to consider

Libsass is C++ library with C API, so in order to use it, it is necessary to provide C++ runtime. This library is linked against libstdc++ (Windows & Linux)/libc++ (macOS) automatically, so you don't have to deal with linking process.

Known limitations

GHCi not able to load hLibSass

GHC 7 is unable to load static version of native libraries (at least some of them) and therefore it rejects loading libsass.a. On Linux, you can overcome this by switch to GHC 8 (tested with 8.0.2 with LTS Haskell 8.5) or by using shared or external (also shared) version of LibSass. On macOS, GHC 8 still rejects the library (it detects unresolver/duplicated symbols), so the only solution is to use shared/external LibSass (Homebrew version works).

Copyright

Copyright (c) 2015-2020 Jakub Fijałkowski. See LICENSE for details.

hlibsass's People

Contributors

jakubfijalkowski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hlibsass's Issues

Windows support

Would you be opening to making this library also work on Windows? When I try to build it on Windows I get the following error:

env: rawSystem: does not exist (No such file or directory)

It looks like this is caused by these two lines in Setup.hs.

https://github.com/jakubfijalkowski/hlibsass/blob/master/Setup.hs#L65
https://github.com/jakubfijalkowski/hlibsass/blob/master/Setup.hs#L72

This is the lowest level Haskell sass library (all the others ultimately depend on this one), so it seems like it would be useful for it to also support Windows. Is this something you would consider?

Build failure: constructors not in scope

Build failure with GHC 8.2.1 as seen on the Stackage build server:

[1 of 1] Compiling Main             ( Setup.hs, Setup.o )

Setup.hs:31:38: error:
    • Data constructor not in scope:
        Version :: [Integer] -> [a0] -> Version
    • Perhaps you meant one of these:
        variable ‘mkVersion’ (imported from Distribution.Simple),
        variable ‘noVersion’ (imported from Distribution.Simple)
   |
31 |         hooksFix = if cabalVersion < Version [1, 20, 0] []
   |                                      ^^^^^^^

Setup.hs:123:52: error:
    • Data constructor not in scope: FlagName :: [Char] -> FlagName
    • Perhaps you meant one of these:
        variable ‘flagName’ (imported from Distribution.PackageDescription),
        variable ‘mkFlagName’ (imported from Distribution.PackageDescription),
        variable ‘unFlagName’ (imported from Distribution.PackageDescription)
    |
123 | getCabalFlag name flags = fromMaybe False (lookup (FlagName name') allFlags)
    |

Setup.hs `makeLibsass` assumes that `make` is GNU make

... but this assumption doesn't work on operating systems where that's not the case.
Setup.hs hard-wires "make"; a better heuristic might be:
if gmake is available, use it by preference, otherwise make.
(Stack does this, but uses RIO's doesExecutableExist.)

(I'll try to come up with a patch, but I'm not hopeful.)

Segmentation Fault with using hlibsass (and by proxy hsass) in ghci

2016-05-20 00:29:40.226610: [warn] The following GHC options are incompatible with GHCi and have not been passed to it: -O2 -threaded @(stack_4Jm00qpelFc1pPl4KgrPav:Stack.Ghci src/Stack/Ghci.hs:134:9)
2016-05-20 00:29:40.226871: [info] Using main module: 1. Package `alldice' component exe:alldice with main-is file: /home/paul/projects/programming/alldice/src/Main.hs @(stack_4Jm00qpelFc1pPl4KgrPav:Stack.Ghci src/Stack/Ghci.hs:199:28)
2016-05-20 00:29:40.227007: [info] Configuring GHCi with the following packages: alldice @(stack_4Jm00qpelFc1pPl4KgrPav:Stack.Ghci src/Stack/Ghci.hs:159:5)
2016-05-20 00:29:40.227271: [debug] Run process: ghc --interactive -i -odir=/home/paul/projects/programming/alldice/.stack-work/odir -hidir=/home/paul/projects/programming/alldice/.stack-work/odir -hide-all-packages -i/home/paul/projects/programming/alldice/src -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/alldice/alldice-tmp -stubdir=/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -lpthread -package-id=base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d -package-id=hsass-0.4.0-c75fc33916942b59209c6f8aaadda002 -package-id=hlibsass-0.1.5.0-55d6cccedbcf8a713482379106202249 -Wall -fno-warn-missing-signatures -rtsopts -optP-include -optP/tmp/ghci20900/cabal_macros.h -ghci-script=/tmp/ghci20900/ghci-script @(stack_4Jm00qpelFc1pPl4KgrPav:Stack.Exec src/Stack/Exec.hs:76:5)
2016-05-20 00:29:40.227620: [debug] Creating process: /home/paul/.stack/programs/x86_64-linux/ghc-7.10.3/bin/ghc --interactive -i -odir=/home/paul/projects/programming/alldice/.stack-work/odir -hidir=/home/paul/projects/programming/alldice/.stack-work/odir -hide-all-packages -i/home/paul/projects/programming/alldice/src -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/autogen -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -i/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build/alldice/alldice-tmp -stubdir=/home/paul/projects/programming/alldice/.stack-work/dist/x86_64-linux/Cabal-1.22.5.0/build -lpthread -package-id=base-4.8.2.0-0d6d1084fbc041e1cded9228e80e264d -package-id=hsass-0.4.0-c75fc33916942b59209c6f8aaadda002 -package-id=hlibsass-0.1.5.0-55d6cccedbcf8a713482379106202249 -Wall -fno-warn-missing-signatures -rtsopts -optP-include -optP/tmp/ghci20900/cabal_macros.h -ghci-script=/tmp/ghci20900/ghci-script @(stack_4Jm00qpelFc1pPl4KgrPav:System.Process.Run src/System/Process/Run.hs:102:5)
GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
zsh: segmentation fault  stack ghci --verbose

It seems like if I only import base + hsass + hlibsass it will crash ghci with segmentation faults.

Build fails with Cabal-3.0

Build fails with Cabal-3.0 with this error:

/private/var/folders/3b/9plp3gb959gcv_nyqg9j_k740000gn/T/stack45489/hlibsass-0.1.8.0/Setup.hs:41:13: error:
     Not in scope: ‘preSDist’
    |
 41 |           , preSDist = updateLibsassVersion
    |             ^^^^^^^^

This seems to be because of using the now removed preSDist hook.

Does not seem to build neatly with stack.

[paul@imaskar:~/projects/programming/alldice] (master) :) $ stack build                                                                                 12:49AM
alldice-0.1.0.0: configure
Configuring alldice-0.1.0.0...
alldice-0.1.0.0: build
Preprocessing executable 'alldice' for alldice-0.1.0.0...
[8 of 8] Compiling Main             ( src/Main.hs, .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/alldice/alldice-tmp/Main.o )

src/Main.hs:4:1: Warning:
    The import of ‘Control.Applicative’ is redundant
      except perhaps to import instances from ‘Control.Applicative’
    To import instances alone, use: import Control.Applicative()
Linking .stack-work/dist/x86_64-linux/Cabal-1.22.4.0/build/alldice/alldice ...
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/../../../../x86_64-pc-linux-gnu/bin/ld: cannot find -lsass
collect2: error: ld returned 1 exit status

--  While building package alldice-0.1.0.0 using:
      /home/paul/.stack/setup-exe-cache/setup-Simple-Cabal-1.22.4.0-x86_64-linux-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.4.0/ build exe:alldice --ghc-options  -ddump-hi -ddump-to-file
    Process exited with code: ExitFailure 1

Basically this is what happens when I try to use this project with stack, it falls apart. I am not for certain the exact reasoning and I'll be linking this ticket to the stack project in case it has to do with the submodule here (libsass). But if I alter my stack config to include:

# Local packages, usually specified by relative directory name
packages:
- '.'
- location: libs/hlibsass
  extra-dep: true

Then make this repo a submodule of my regular repo, and force the libsass submodule to load, stack is able to build and relink against the project over and over just fine.

Trouble installing on Mac OS X

Hi, just wondering if you or anyone else out there has tried using this on OS X. I read the installation instructions and tried all the flags in order. Here's what happens:

No flag:

ghc:
lookupSymbol failed in relocateSection (RELOC_GOT)
/Users/mohanzhang/code/hq/.stack-work/install/x86_64-osx/lts-2.17/7.8.4/lib/x86_64-osx-ghc-7.8.4/hlibsass-0.1.4.0/libsass.a: unknown symbol `___dso_handle'
ghc: unable to load package `hlibsass-0.1.4.0'

with sharedLibsass:

<command line>: can't load .so/.DLL for: /Users/mohanzhang/code/hq/.stack-work/install/x86_64-osx/lts-2.17/7.8.4/lib/x86_64-osx-ghc-7.8.4/hlibsass-0.1.4.0/libHShlibsass-0.1.4.0-ghc7.8.4.dylib (dlopen(/Users/mohanzhang/code/hq/.stack-work/install/x86_64-osx/lts-2.17/7.8.4/lib/x86_64-osx-ghc-7.8.4/hlibsass-0.1.4.0/libHShlibsass-0.1.4.0-ghc7.8.4.dylib, 9): Library not loaded: lib/libsass.so
  Referenced from: /Users/mohanzhang/code/hq/.stack-work/install/x86_64-osx/lts-2.17/7.8.4/lib/x86_64-osx-ghc-7.8.4/hlibsass-0.1.4.0/libHShlibsass-0.1.4.0-ghc7.8.4.dylib
  Reason: image not found)

with externalLibsass (it builds much quicker since it's not building its own libsass, but still fails in the same way as building with no flags. I used homebrew to install libsass. Is it expecting to find it in a specific place?):

ghc:
lookupSymbol failed in relocateSection (RELOC_GOT)
/Users/mohanzhang/code/hq/.stack-work/install/x86_64-osx/lts-2.17/7.8.4/lib/x86_64-osx-ghc-7.8.4/hlibsass-0.1.4.0/libsass.a: unknown symbol `___dso_handle'
ghc: unable to load package `hlibsass-0.1.4.0'

Any ideas? Thanks!

Update to libsass 3.6.3

libsass releases 3.6 onward have a lot of new features which will be great to have in hlibsass as well.

some pb with intero

The default configuration has intero say

GHC runtime linker: fatal error: I found a duplicate definition for symbol
   __ZN4Sass7EmitterD0Ev
whilst processing object file
   /Users/nrolland/.stack/snapshots/x86_64-osx/nightly-2017-01-14/8.0.1/lib/x86_64-osx-ghc-8.0.1/hlibsass-0.1.5.0-DAuvZ5FMWJ2GN3MaQufO80/libsass.a
The symbol was previously defined in
   /Users/nrolland/.stack/snapshots/x86_64-osx/nightly-2017-01-14/8.0.1/lib/x86_64-osx-ghc-8.0.1/hlibsass-0.1.5.0-DAuvZ5FMWJ2GN3MaQufO80/libsass.a(emitter.o)
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
     loaded twice.
intero: Could not on-demand load symbol '__ZN4Sass14Operation_CRTPIvNS_7InspectEEclEPNS_12Custom_ErrorE'

intero: 
lookupSymbol failed in relocateSection (RELOC_GOT)
/Users/nrolland/.stack/snapshots/x86_64-osx/nightly-2017-01-14/8.0.1/lib/x86_64-osx-ghc-8.0.1/hlibsass-0.1.5.0-DAuvZ5FMWJ2GN3MaQufO80/libsass.a: unknown symbol `___dso_handle'
intero: Could not on-demand load symbol '__ZN4Sass14Memory_Manager3addEPNS_13Memory_ObjectE'

intero: 
lookupSymbol failed in relocateSection (relocate external)
/Users/nrolland/.stack/snapshots/x86_64-osx/nightly-2017-01-14/8.0.1/lib/x86_64-osx-ghc-8.0.1/hlibsass-0.1.5.0-DAuvZ5FMWJ2GN3MaQufO80/libsass.a: unknown symbol `__ZN4Sass14Memory_Manager3addEPNS_13Memory_ObjectE'
intero: Could not on-demand load symbol '__ZN4Sass6Parser3lexIXadL_ZNS_8Prelexer10identifierEPKcEEEES4_bb'

Using an external libsass involves installing it globally brew install libsass and adding to the stack.yaml:

extra-deps:
- hlibsass-0.1.5.0

# Override default flag values for local packages and extra-deps
flags:
      hlibsass:
        externalLibsass: true  

Now intero should work.

It might be useful to add it to the readme.

Updated Needed

Something similar to #3 seems to be happening again, where the latest version of libsass isn't supported.

Can someone else confirm though? I'm not super confident this is what's going wrong. I'm coming from NixOS/nixpkgs#38253.

Troubles Installing on Windows10

Hi there, just wondering if you or anyone else out there has tried using this on Windows10. I read the installation instructions, but here's what happens:

env: make: No such file or directory -- While building custom Setup.hs for package hlibsass-0.1.6.1 using: C:\Users\Kilian\hlibsass\.stack-work\dist\ca59d0ab\setup\setup --builddir=.stack-work\dist\ca59d0ab configure --with-ghc=C:\Users\Kilian\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc.EXE --with-ghc-pkg=C:\Users\Kilian\AppData\Local\Programs\stack\x86_64-windows\ghc-8.0.2\bin\ghc-pkg.EXE --user --package-db=clear --package-db=global --package-db=C:\sr\snapshots\62cfb14b\pkgdb --package-db=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\pkgdb --libdir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\lib --bindir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\bin --datadir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\share --libexecdir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\libexec --sysconfdir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\etc --docdir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\doc\hlibsass-0.1.6.1 --htmldir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\doc\hlibsass-0.1.6.1 --haddockdir=C:\Users\Kilian\hlibsass\.stack-work\install\6c953ab2\doc\hlibsass-0.1.6.1 --dependency=Cabal=Cabal-1.24.2.0 --dependency=base=base-4.9.1.0 --dependency=directory=directory-1.3.0.0 --extra-include-dirs=C:\Users\Kilian\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\include --extra-lib-dirs=C:\Users\Kilian\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\bin --extra-lib-dirs=C:\Users\Kilian\AppData\Local\Programs\stack\x86_64-windows\msys2-20150512\mingw64\lib --enable-benchmarks Process exited with code: ExitFailure 127

Please correct me if i did domething wrong here.

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.