From 06e356d0ab099db78b1097fa74a4773aeed04e62 Mon Sep 17 00:00:00 2001 From: Vladimir Kravets Date: Mon, 6 Jan 2025 16:44:55 +0200 Subject: [PATCH] Add devshell for nix under macOs --- .envrc | 5 +++ CMakeLists.txt | 25 +++++++++++++-- README-OSX.md | 15 ++++++++- flake.lock | 43 ++++++++++++++++++++++++++ flake.nix | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 167 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..82df86df42 --- /dev/null +++ b/.envrc @@ -0,0 +1,5 @@ +if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" +fi + +use flake . --impure diff --git a/CMakeLists.txt b/CMakeLists.txt index e09ce84509..793f388fc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,12 @@ option ( ENABLE_CLANG_ANALYSIS "When building with clang, enable the static anal option ( CHECK_CCACHE "Check if ccache is installed and use it" OFF ) set ( MSVC_WARNING_LEVEL 3 CACHE STRING "Visual Studio warning levels" ) option ( FORCE_INSTALL_DATA_TO_BIN "Force installation of data to binary directory" OFF ) +if ( APPLE ) + # Use by default since brew doesn't have legacy SDL1, sdl12-compat avalaible + option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" ON ) +else () + option ( USE_SDL2 "Using SDL2 via SDL12 compatible layer" OFF ) +endif () set ( DATADIR "" CACHE STRING "Where to search for datafiles" ) if ( CHECK_CCACHE ) @@ -91,17 +97,30 @@ if(NOT UNIX AND IS_DIRECTORY ${DEPS_DIR}) else ( ) link_directories ( ${DEPS_DIR}/lib/Win32 ) endif() - set( SDL_LIBRARY SDL ) + set ( SDL_LIBRARY SDL ) + if ( USE_SDL2 ) + # explicitly added SDL2 as dependency since needed for runtime work + set ( SDL2_LIBRARY SDL2 ) + message ( STATUS "Using SDL2 via SDL12 compatible layer" ) + else ( ) + set ( SDL2_LIBRARY "") + endif () set ( SDLGFX_LIBRARY SDL_gfx ) set ( SDLMIXER_LIBRARY SDL_mixer ) set ( SDLIMAGE_LIBRARY SDL_image ) - set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${OPENGL_LIBRARIES} ) + set ( PKG_DEPS_LDFLAGS ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLGFX_LIBRARY} ${SDL_LIBRARY} ${SDL2_LIBRARY} ${OPENGL_LIBRARIES} ) elseif(UNIX OR MINGW OR CYGWIN) if(IS_DIRECTORY ${DEPS_DIR}) set(ENV{PKG_CONFIG_PATH} "${DEPS_DIR}/lib/pkgconfig/") endif() include(FindPkgConfig) + if ( USE_SDL2 ) + # explicitly added SDL2 as dependency since needed for runtime work + pkg_check_modules(PKG_SDL2 REQUIRED sdl2) + else ( ) + set ( PKG_SDLG2_LDFLAGS "" ) + endif () pkg_check_modules(PKG_SDL REQUIRED sdl) pkg_check_modules(PKG_ZLIB REQUIRED zlib) pkg_check_modules(PKG_SDLIMAGE REQUIRED SDL_image) @@ -110,7 +129,7 @@ elseif(UNIX OR MINGW OR CYGWIN) include_directories(${PKG_SDL_INCLUDE_DIRS} ${PKG_ZLIB_INCLUDE_DIRS} ${PKG_SDLIMAGE_INCLUDE_DIRS}) include_directories(${PKG_SDLGFX_INCLUDE_DIRS} ${PKG_SDLMIXER_INCLUDE_DIRS}) - set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES}) + set(PKG_DEPS_LDFLAGS ${PKG_SDL_LDFLAGS} ${PKG_SDL2_LDFLAGS} ${PKG_ZLIB_LDFLAGS} ${PKG_SDLIMAGE_LDFLAGS} ${PKG_SDLGFX_LDFLAGS} ${PKG_SDLMIXER_LDFLAGS} ${OPENGL_LIBRARIES}) if (UNIX) set(PKG_DEPS_LDFLAGS "${PKG_DEPS_LDFLAGS};dl") diff --git a/README-OSX.md b/README-OSX.md index fba1ae2ea5..737db98cad 100644 --- a/README-OSX.md +++ b/README-OSX.md @@ -1,6 +1,8 @@ # Building for MacOS -## Dependencies +## Using brew + +### Dependencies To successfully build an OpenXcom OSX bundle you will need to ensure all the relevant dependencies installed in /usr/local/. The dependencies you require are following: @@ -16,6 +18,17 @@ $ brew install cmake sdl sdl_gfx sdl_image sdl_mixer --with-flac --with-libmikmo ``` This should install all of these necessary dependencies to their appropriate place under /usr/local. + +## Using Nix + +All needed stuff related to installing and configure shell already described at flake.nix, just execute + +``` +$ nix develop -c $SHELL +``` + +Note: After it all below building command are applicable + ## Building This project has two ways to build: one with make and the other with Xcode. The make way is typically used for CI builds and produces a similar artifact as the Linux build. If you're just looking to get a quick build, this is a good way to do so. The Xcode way is useful if you're developing features (or bug fixes) and require the need for a debugger or an IDE experience. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..9c4eddcdf7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1737622296, + "narHash": "sha256-GWHH9ljsR0LR29IEruJnKVVk6veeQpo7kfolyDyCVGQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "055c50feaa548eadca66407630961b77f3ebb750", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..447da47d74 --- /dev/null +++ b/flake.nix @@ -0,0 +1,83 @@ +{ + inputs = { + systems.url = "github:nix-systems/default"; + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + }; + + outputs = + { + self, + nixpkgs, + systems, + }: + let + forEachSystem = + f: nixpkgs.lib.genAttrs (import systems) (system: f { pkgs = import nixpkgs { inherit system; }; }); + in + { + devShells = forEachSystem ( + { pkgs }: + { + default = + pkgs.mkShell.override + { + # override clang 16 runtime + stdenv = pkgs.lowPrio pkgs.llvmPackages_16.stdenv; + } + { + propagatedBuildInputs = [ + pkgs.SDL_compat + pkgs.SDL_image + pkgs.libwebp + ]; + + buildInputs = with pkgs; [ + git + pkg-config + apple-sdk_15 + + # Need to use brew cmake since nix use old one 3.30.5 + # which has issues with copy libraries to macOs app + cmake + # use clang explicitly since don't use cmake + clang_16 + # OpenXcom dependecies + rapidyaml + zlib + #SDL_mixer + # SDL_image + # SDL_gfx + # Try to build using SDL12_compat + (SDL_compat.overrideAttrs (old: { + postInstall = '' + ln -s $out/lib/pkgconfig/sdl12_compat.pc $out/lib/pkgconfig/sdl.pc + ''; + })) + (SDL_mixer.override (old: { + SDL = SDL_compat; + smpeg = old.smpeg.override { + SDL = SDL_compat; + }; + })) + (SDL_gfx.override (old: { + SDL = SDL_compat; + })) + ( + (SDL_image.override (old: { + SDL = SDL_compat; + })).overrideAttrs + (old: { + propagatedBuildInputs = [ SDL_compat ]; + src = pkgs.fetchurl { + url = "https://github.com/libsdl-org/SDL_image/archive/refs/heads/SDL-1.2.tar.gz"; + hash = "sha256-ytt87YL2zrvLun7bi5Jd4m5N7/UR09Y3I1kRDAqf6nQ="; + }; + patches = [ ]; + }) + ) + ]; + }; + } + ); + }; +}