-1

I want to build pyobjc-7.3, because it has fix for send2trash. Classic building on BigSur 20.5.0 is strait forward.

cd pyobjc-7.3/pyobjc-framework-Cocoa
python3 setup.py build

though once I run same build inside nix-shell magic happens.

nix-shell -p pkgs.python39Packages.setuptools
python3 setup.py build

clang-7: error: argument unused during compilation: '-fno-strict-overflow' [-Werror,-Wunused-command-lin\ e-argument]

ok. no big deal. let's disable warning.

CFLAGS="-Wno-unused-argument" python3 setup.py build

what? now clang is like a blind kitten.

Modules/pyobjc-api.h:19:10: fatal error: 'objc/objc.h' file not found #include <objc/objc.h>

-isysroot option and -I has no effect.

-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk

I noticed lots additions to -I flag in clang such as:

-iwithprefix /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include

it helps clang to find objc header file, though this is not the end of the story.

Modules/pyobjc-api.h:21:9: fatal error: 'Foundation/Foundation.h' file not found

how come?! oh there is another header files of special kind - frameworks. Wheel reinvention...

clang, take another argument

-iframeworkwithsysroot /System/Library/Frameworks

Here I get tons of type errors and I run out of ideas what could I try next:

/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:138:1: error: function cannot return function type 'NSComparisonResult' (aka 'int (int)')

  • (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSR...
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
  • Nix is a "hermetic" build system, meaning that you have to specify all dependencies. Without those, builds would not be reproducible. If you want to package pyobjc, you could look at similar packages in Nixpkgs. If you only want to build it in `nix-shell`, I would recommend to write a file as if you were packaging it, so you can use `nix-shell` with that file. `nix-shell -p` can only set `buildInputs`, which can be too limiting. – Robert Hensing Jul 26 '21 at 08:48

1 Answers1

0

After days of trying I've found solution. There are a few bugs are causing the problems:

First is nix provides older (10.12) sdk while setup.py thinks is 10.15. This enables CPP sections for unsupported SDK API therefore type errors. Following hack makes pyobjc to think that SDK is older that it is.

with pkgs;
with pkgs.lib;
with pkgs.python39Packages;

let
  pyobjc-core = buildPythonPackage rec {
    pname = "pyobjc-core";
    version = "7.3";
    name = "${pname}-${version}";
    src = pkgs.python39Packages.fetchPypi {
      pname = "pyobjc-core";
      inherit version;
      sha256 = "0x3msrzvcszlmladdpl64s48l52fwk4xlnnri8daq2mliggsx0ah";
    };
    preBuild=''                                                                                                               
         export SDKROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX10.12.sdk"

Second problem is with header discovery and overstrict lint from python nix

CFLAGS = "-iwithsysroot /usr/include -Wno-unused-argument";

Third problem big sur linkder is dynamic and ffi libray is not found. Providing through nix derivation

    buildInputs = [ pkgs.libffi ];

Forth problem is tests are broken

    doCheck = false;
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49