Skip to content

Fails to build in a nix derivation #27

@harendra-kumar

Description

@harendra-kumar

nix-develop fails with this error;

       > [3 of 3] Linking dist/build/FileSystem.Event.Darwin/FileSystem.Event.Darwin
       > Undefined symbols for architecture x86_64:
       >   "_FSEventStreamEventFlagItemCloned", referenced from:
       >       _streamlyzmfseventszm0zi1zi0zm3vXYsi9XG6MJY5kSD8JwQW_StreamlyziInternalziFSziEventziDarwin_isClonedzumask_info in libHSstreamly-fsevents-0.1.0-3vXYsi9XG6MJY5kSD8JwQW.a(Darwin.o)
       > ld: symbol(s) not found for architecture x86_64
       > clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
       > ghc-9.6.6: `cc' failed in phase `Linker'. (Exit code: 1)
       > <<ghc: 78659072 bytes, 1 GCs, 5266776/5266776 avg/max bytes residency (1 samples), 804M in use, 0.016 INIT (0.016 elapsed), 0.237 MUT (3.934 elapsed), 0.010 GC (0.012 elapsed) :ghc>>
       For full logs, run:
         nix-store -l /nix/store/6l2br46v48lkchgnqfscp0hxzwmg958j-streamly-fsevents-0.1.0.drv
error: 1 dependencies of derivation '/nix/store/hr4ja4hi1xny3nqcs17ic1kp6ggzhhmq-ghc-9.6.6-with-packages.drv' failed to build

When using nix-develop what happens is:

  1. The SDK is newer (10.15.6 in the log).
  2. The deployment target is older (10.12.0).
  3. Clang says: “Yes, this symbol exists, but it’s guarded by availability macros.” → configure interprets that as “symbol exists,” so it sets HAVE_DECL_KFSEVENTSTREAMEVENTFLAGITEMCLONED=1.
  4. Later, when the code tries to actually use it, the linker fails (because the symbol isn’t exposed at runtime for 10.12).

So configure wrongly sets HAVE_DECL_KFSEVENTSTREAMEVENTFLAGITEMCLONED=1.

In nix-shell somehow the SDK pulled is 10.12 and the deployment target is also 10.12 - therefore, it build correctly.

src/Streamly/Internal/FS/Event/Darwin.c

#include <CoreServices/CoreServices.h>

#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
UInt32 FSEventStreamEventFlagItemCloned () {
  return kFSEventStreamEventFlagItemCloned;
}
#endif

src/Streamly/Internal/FS/Event/Darwin.hs

{-# LANGUAGE CPP #-}

module Streamly.Internal.FS.Event.Darwin
    ( isCloned
    ) where

import Data.Word (Word32)

#if HAVE_DECL_KFSEVENTSTREAMEVENTFLAGITEMCLONED
foreign import ccall safe
    "FSEventStreamEventFlagItemCloned"
    kFSEventStreamEventFlagItemCloned :: Word32

-- | Determine whether the event indicates cloning of an object within the
-- monitored path. The "Duplicate" command in the "File" menu of the "Finder"
-- application generates a "clone" event.
--
-- Applicable only when 'setFileEvents' is 'True'.
--
-- /macOS 10.13+/
--
-- /Pre-release/
--
isCloned :: Event -> Bool
isCloned = getFlag kFSEventStreamEventFlagItemCloned
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions