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

MacOS Arm build test #41

Merged
merged 17 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,11 @@ jobs:
path: artifact/

build-macos:
name: MacOS 10.13
name: MacOS Fat
runs-on: macos-latest
steps:
- name: Checkout Files
uses: actions/checkout@v4
- name: Setup MacOS
run: brew install make gcc@13 cmake
# brew's gcc has to be a specific version, make sure to update 13 above and below if upgrading
- name: Submodule Cache Key
run: |
echo "SDLHASH=$(git submodule status SDL | tr -d '[:blank:]')" >> $GITHUB_ENV
Expand All @@ -172,23 +169,51 @@ jobs:
with:
path: |
SDL/build
zlib_build
zlib_build_arm
zlib_build_intel
key: sub-macos-${{ env.SDLHASH }}-${{ env.ZLIBHASH }}
- name: Build SDL2 and zlib
if: steps.cache-sub.outputs.cache-hit != 'true'
run: |
export CC=/usr/local/bin/gcc-13
export CC=clang
export CFLAGS="-target arm64-apple-macos11"
export ZLIB_BUILD=zlib_build_arm
make -f makefile.zlib
export CC=gcc-13
export CFLAGS=-mmacosx-version-min=10.13
export ZLIB_BUILD=zlib_build_intel
make -f makefile.zlib
export CFLAGS=
export CC=$(PWD)/SDL/build-scripts/clang-fat.sh
make -f makefile.sdl
- name: Build hatariB
run: |
export OS=MacOS
export CC=/usr/local/bin/gcc-13
export CC_OLD=$CC
export BD=build_arm
export HBD=build_arm
export ZLIB_BUILD=zlib_build_arm
export CMAKEFLAGS="-DCMAKE_C_COMPILER=clang -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_SYSTEM_NAME=Darwin"
make hatarilib
export CC=clang
export CFLAGS="-target arm64-apple-macos11"
export LDFLAGS="-target arm64-apple-macos11"
make core
export BD=build_intel
export HBD=build_intel
export ZLIB_BUILD=zlib_build_intel
export CC=$CC_OLD
export CFLAGS=
export LDFLAGS=
export CMAKEFLAGS="-DCMAKE_C_COMPILER=gcc-13 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13 -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_SYSTEM_NAME=Darwin"
make hatarilib
export CC=gcc-13
export CFLAGS=-mmacosx-version-min=10.13
export CMAKEFLAGS="-DCMAKE_C_COMPILER=/usr/local/bin/gcc-13 -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13"
gmake
export LDFLAGS="-mmacosx-version-min=10.13 -static-libgcc"
make core
strip -u -r build_arm/hatarib.dylib
strip -u -r build_intel/hatarib.dylib
mkdir -p build
lipo -create -output build/hatarib.dylib build_arm/hatarib.dylib build_intel/hatarib.dylib
- name: Prepare Artifact
run: |
mkdir artifact
Expand Down
10 changes: 7 additions & 3 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Otherwise there are minor changes to the CMake build files, each marked with a c
* Saved `MachineClocks` (from clocks_timings.c) to prevent state divergence.
* Use standardized path length for snapshot of filenames.
* Remove unsupported Lilo and DiskZip paths.
* **hatari/src/cfgopts.c**
* Suppress unused variable warning.
* **hatari/src/crossbar.c**
* Removed `Crossbar_Recalculate_Clocks_Cycles()` from savestate restore because it seemed to be unnecessary and caused state divergence.
* **hatari/src/cycInt.c**
Expand Down Expand Up @@ -270,13 +272,15 @@ Otherwise there are minor changes to the CMake build files, each marked with a c
* Replace use of `rand()` with deterministic `core_rand()`.
* **hatari/src/zip.c**
* Disable use of `unzOpen` which was modified (see: unzip.c) and not needed by this core.
* **hatari/cpu/custom.c**
* **hatari/src/cpu/custom.c**
* Make `extra_cycle` externally accessible for savestate.
* **hatari/src/cpu/gencpui.c**
* Suppress unused variable warning.
* **hatari/cpu/hatari-glue.c**
* Added `core_save_state`, `core_restore_state` and `core_flush_audio` to facilitate seamless savestates.
* **hatari/cpu/memory.c**
* **hatari/src/cpu/memory.c**
* Disable `SDL_Quit`.
* **hatari/cpu/newcpu.c**
* **hatari/src/cpu/newcpu.c**
* Split `m68k_go` into `m68k_go`, `m68k_go_frame`, and `m68k_go_quit` to allow emulation loop to return to the Libretro core after each frame.
* `m68k_go` initializes the CPU and prepares to emulate the first frame before it exits. This is the last thing done during `retro_init`.
* `m68k_go_frame` runs the main emulation loop, returning after one frame. This is called once each frame from `retro_run`.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A [Libretro](https://www.libretro.com/) core integrating the [Hatari](https://ha
* Current Build Platforms:
* Windows 64-bit, 32-bit
* Ubuntu
* MacOS
* MacOS 11.0 Apple Arm, 10.13 Intel 64-bit
* Raspberry Pi OS 64-bit, 32-bit
* Android 64-bit, 32-bit
* Current Release:
Expand Down Expand Up @@ -272,6 +272,7 @@ See [DEVELOP.md](DEVELOP.md) for more details.
* Fixed out-of-date screen image during pause/one-shot and savestate/netplay/run-ahead.
* Android builds.
* Multiple hard disk support.
* MacOS Fat build (Intel 64-bit, Apple Arm).
* [hatariB v0.2](https://github.com/bbbradsmith/hatariB/releases/tag/0.2) - 2023-09-07
* Second beta test version.
* IPF support via dynamic loading of capsimg library.
Expand Down
3 changes: 3 additions & 0 deletions hatari/src/cfgopts.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ int update_config(const char *filename, const struct Config_Tag configs[], const
char line[1024];
bool bUseTempCfg = false;
const char *sTempCfgName = "_temp_.cfg";
#ifdef __LIBRETRO__
(void)lineno;
#endif

cfgfile = fopen(filename, "r");

Expand Down
3 changes: 3 additions & 0 deletions hatari/src/cpu/gencpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,9 @@ static int gence020cycles_ciea (struct instr *curi, wordsizes ssize, amodes dmod
static int gence020cycles_fea (amodes mode)
{
int h = 0, t = 0, c = 0, ws = 0;
#ifdef __LIBRETRO__
(void)ws;
#endif
switch ((int)mode)
{
case Dreg:
Expand Down
61 changes: 36 additions & 25 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# BD = core build directory
# HBD = hatari build subdirectory
BD ?= build
HBD ?= build
ZLIB_BUILD ?= zlib_build

# enables debug symbols, CPU trace logging
DEBUG ?= 0

Expand All @@ -14,9 +20,9 @@ WERROR ?= -Wall -Werror
SHORTHASH = "$(shell git rev-parse --short HEAD || unknown)"

# static libraries
ZLIB_INCLUDE ?= $(PWD)/zlib_build/include
ZLIB_INCLUDE ?= $(PWD)/$(ZLIB_BUILD)/include
SDL2_INCLUDE ?= $(PWD)/SDL/build/include/SDL2
ZLIB_LIB ?= $(PWD)/zlib_build/lib/libz.a
ZLIB_LIB ?= $(PWD)/$(ZLIB_BUILD)/lib/libz.a
SDL2_LIB ?= $(PWD)/SDL/build/lib/libSDL2.a
SDL2_LINK ?= $(shell $(PWD)/SDL/build/bin/sdl2-config --static-libs)
ZLIB_LINK ?= $(ZLIB_LIB)
Expand All @@ -27,9 +33,9 @@ CC ?= gcc
CFLAGS += \
-O3 $(WERROR) -fPIC \
-D__LIBRETRO__ -DSHORTHASH=\"$(SHORTHASH)\" \
-Ihatari/build -I$(SDL2_INCLUDE)
-Ihatari/$(HBD) -I$(SDL2_INCLUDE)
LDFLAGS += \
-shared $(WERROR) -static-libgcc
-shared $(WERROR)

CMAKE ?= cmake
CMAKEFLAGS += \
Expand All @@ -50,9 +56,9 @@ ifneq ($(DEBUG),0)
LDFLAGS += -g
CMAKEFLAGS += -DENABLE_TRACING=1
else
ifneq ($(OS),MacOS)
LDFLAGS += -Wl,--strip-debug
endif
ifneq ($(shell uname),Darwin)
LDFLAGS += -Wl,--strip-debug
endif
CMAKEFLAGS += -DENABLE_TRACING=0
endif

Expand All @@ -65,34 +71,39 @@ endif

ifeq ($(OS),Windows_NT)
SO_SUFFIX=.dll
else ifeq ($(OS),MacOS)
LDFLAGS += -static-libgcc
else ifeq ($(shell uname),Darwin)
SO_SUFFIX=.dylib
else
SO_SUFFIX=.so
LDFLAGS += -static-libgcc
endif

BD=build/
CORE=$(BD)hatarib$(SO_SUFFIX)
CORE=$(BD)/hatarib$(SO_SUFFIX)
SOURCES = \
core/core.c \
core/core_file.c \
core/core_input.c \
core/core_disk.c \
core/core_config.c \
core/core_osk.c
OBJECTS = $(SOURCES:%.c=$(BD)%.o)
OBJECTS = $(SOURCES:%.c=$(BD)/%.o)
HATARILIBS = \
hatari/build/src/libcore.a \
hatari/build/src/falcon/libFalcon.a \
hatari/build/src/cpu/libUaeCpu.a \
hatari/build/src/gui-sdl/libGuiSdl.a \
hatari/build/src/libFloppy.a \
hatari/build/src/debug/libDebug.a \
hatari/build/src/libcore.a \
hatari/$(HBD)/src/libcore.a \
hatari/$(HBD)/src/falcon/libFalcon.a \
hatari/$(HBD)/src/cpu/libUaeCpu.a \
hatari/$(HBD)/src/gui-sdl/libGuiSdl.a \
hatari/$(HBD)/src/libFloppy.a \
hatari/$(HBD)/src/debug/libDebug.a \
hatari/$(HBD)/src/libcore.a \
$(ZLIB_LINK) $(SDL2_LINK)
# note: libcore is linked twice to allow other hatari internal libraries to resolve references within it.

default: $(CORE)
.PHONY: default core

default: core

core: $(CORE)

# clean and rebuild everything (including static libs)
full:
Expand All @@ -118,19 +129,19 @@ sdlreconfig:

directories:
mkdir -p $(BD)
mkdir -p $(BD)core
mkdir -p hatari/build
mkdir -p $(BD)/core
mkdir -p hatari/$(HBD)

$(CORE): directories hatarilib $(OBJECTS)
$(CC) -o $(CORE) $(LDFLAGS) $(OBJECTS) $(HATARILIBS)

$(BD)core/%.o: core/%.c hatarilib
$(BD)/core/%.o: core/%.c hatarilib
$(CC) -o $@ $(CFLAGS) -c $<

hatarilib: directories
(cd hatari/build && export CFLAGS="$(CFLAGS)" && $(CMAKE) .. $(CMAKEFLAGS))
(cd hatari/build && export CFLAGS="$(CFLAGS)" && $(CMAKE) --build . $(CMAKEBUILDFLAGS))
(cd hatari/$(HBD) && export CFLAGS="$(CFLAGS)" && $(CMAKE) .. $(CMAKEFLAGS))
(cd hatari/$(HBD) && export CFLAGS="$(CFLAGS)" && $(CMAKE) --build . $(CMAKEBUILDFLAGS))

clean:
rm -f -r $(BD)
rm -f -r hatari/build
rm -f -r hatari/$(HBD)
4 changes: 2 additions & 2 deletions makefile.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ submodules:
git submodule update --depth 1

sdl: submodules
mkdir -p SDL/build
mkdir -p $(SDL_PREFIX)
export CFLAGS="$(CFLAGS)" && cd SDL/build && ../configure --disable-shared --prefix=$(SDL_PREFIX) $(CONFIGURE_FLAGS) \
--enable-audio=no --enable-power=no --enable-filesystem=no --enable-timers=no --enable-file=no \
--enable-events=no --enable-render=no --enable-loadso=no --enable-cpuinfo=no --enable-assembly=no --enable-atomic=no \
Expand All @@ -40,4 +40,4 @@ sdl: submodules
cd SDL/build && $(MAKE) install

clean:
rm -f -r SDL
rm -f -r $(SDL_PREFIX)
15 changes: 8 additions & 7 deletions makefile.zlib
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
ZLIB_BUILD = $(PWD)/zlib_build
ZLIB_BUILD ?= zlib_build
ZLIB_PREFIX = $(PWD)/$(ZLIB_BUILD)
CFLAGS += -fPIC
# -fPIC needed to link into a shared object

default: $(ZLIB_BUILD)/libz.a
default: $(ZLIB_BUILD)/lib/libz.a

submodules:
git submodule init
git submodule update --depth 1

$(ZLIB_BUILD)/libz.a: submodules
$(ZLIB_BUILD)/lib/libz.a: submodules
mkdir -p $(ZLIB_BUILD)
cd zlib_build && export CFLAGS="$(CFLAGS)" && ../zlib/configure --static --prefix=$(ZLIB_BUILD)
cd zlib_build && $(MAKE) static
cd zlib_build && $(MAKE) install
cd $(ZLIB_BUILD) && export CFLAGS="$(CFLAGS)" && ../zlib/configure --static --prefix=$(ZLIB_PREFIX)
cd $(ZLIB_BUILD) && $(MAKE) static
cd $(ZLIB_BUILD) && $(MAKE) install

clean:
rm -f -r zlib
rm -f -r $(ZLIB_BUILD)