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

Add spec aarch64-apple-darwin9 (Apple Silicon) #11

Merged
merged 3 commits into from
Sep 14, 2024

Conversation

iamFIREcracker
Copy link
Contributor

@iamFIREcracker iamFIREcracker commented Nov 4, 2023

This PR adds specs for Apple Silicon, finally making it possible to run Sketch on newer macs (see related links below). Also, tested on a MacBook Air M2 and it all seems to be working just fine.

Steps to regenerate the specs (I used nix)

First off, force quicklisp to use a version of cl-sdl2 which supports Apple Silicon (e.g., you can clone my fork into ~/quicklisp/local-projects, or wherever your quicklisp installation lives). Note: you won't need this step anymore once changes are merged upstream (see: lispgames/cl-sdl2#167).

Next, drop the following lines in a file named shell.nix at the root of the repository, and then, in the same directory, run nix-shell (this will take care of installing SDL2_image and c2ffi).

shell.nix
let
  pkgs =
    import (
      fetchTarball {
        name = "nixos-23.05_2023-09-18";
        url =
          "https://github.com/NixOS/nixpkgs/archive/f81112bbb0f357b80333300c4702ff7538096156.tar.gz";
        sha256 = "0pxhiggxl5drnpva9287w136rrykcd7xk1nyh655wgf6sb38a82k";
      }
    )
    {};
in
  pkgs.mkShell {
    packages = [
      pkgs.SDL2
      pkgs.SDL2_image
      pkgs.c2ffi
    ];

    LD_LIBRARY_PATH = "${pkgs.SDL2}/lib:${pkgs.SDL2_image}/lib";
    /* SDL2/SDL2_image would import SDL like "SDL.h" and not like "SDL2/SDL.h"
       so to let c2ffi resolve that import correctly, we need to include
       ${pkgs.SDL2.dev}/include/SDL2 and not ${pkgs.SDL2.dev}/include */
    C_INCLUDE_PATH = "${pkgs.SDL2.dev}/include/SDL2:${pkgs.SDL2_image}/include";
  }

Remove the already existing specs (autowrap will try to generate the spec files only if missing):

$ rm -f src/spec/SDL_image.*.spec

Load :SDL2-IMAGE (this will get autowrap to generate the various spec files:

$ sbcl \
	--load "sdl2-image.asd" \
	--eval "(ql:quickload '(:sdl2-image))" \
	--eval "(uiop:quit)"

PS. I also changed autowrap to allow parsing of C_INCLUDE_PATH env variable; let me know if you preferred that to be moved into a separate PR instead.

src/autowrap.lisp Outdated Show resolved Hide resolved
@@ -8,6 +8,7 @@
"/usr/include/"
"/usr/include/arm-linux-gnueabihf"
"/usr/local/include/SDL2")
:sysincludes `,(uiop:split-string (uiop:getenv "C_INCLUDE_PATH") :separator ":")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, OK, but can you make the inclusion of :sysincludes conditional on C_INCLUDE_PATH being set? I do not know what :sysincludes nil does to other platforms. Also, can you document how to use this, even just in a comment? Does nix shell automatically export C_INCLUDE_PATH or is the idea the user has to set it prior to doing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find a way to set :SYSINCLUDES conditionally to the presence of the C_INCLUDE_PATH environment variable; however, I did take a look at the C-INCLUDE macro-expansion, and sysincludes just gets EVAL-d, and since it's initialized with NIL, it should not make a difference if we pass an empty list or omit it altogether.

Also, to address your question about C_INCLUDE_PATH, I went on and added a new section to the README explaining how to regenerate bindings and how C_INCLUDE_PATH can be used if the default configuration was not working.

This gives users a little bit of flexibility and allow them to generate
specs in non-standard environments (e.g. a nix shell), without changing
the autowrap definition.
@fitzsim fitzsim merged commit 784f164 into lispgames:master Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants