compiler icon indicating copy to clipboard operation
compiler copied to clipboard

[DIY] Build from source on Apple Chip M1 using rosetta2

Open soknifedev opened this issue 1 year ago • 6 comments

This is not an issue, is just a tip to build the compiler and run it on Apple M1 Chip computers.

Issue description:

There were multiple people trying to build and run the compiler in macOS ARM/M1: #663 #662 #79 #76 #75 And me, of course.

Instructions

  1. First, you must install Rosetta2, open your Terminal and type:
softwareupdate --install-rosetta --agree-to-license
  1. Follow the guide Building on macOS but do not execute these commands:
cmake ../source/compiler -DCMAKE_C_FLAGS=-m32 -DCMAKE_BUILD_TYPE=Release
make
  1. We will use rosetta2 to compile a 64-bit compatible binary, in your terminal type:
arch -x86_64 zsh -l

(Note that I'm using zsh as shell, if you use bash or anything else, replace it with yours) 4. Verify that your current terminal is using rosetta:

arch

Should output:

i386
  1. Force 32-bit cells

First, modify source/amx/amx.h: Replace this:

#if !defined PAWN_CELL_SIZE
  #define PAWN_CELL_SIZE 32     /* by default, use 32-bit cells */
#endif
#if PAWN_CELL_SIZE==16
  typedef uint16_t  ucell;
  typedef int16_t   cell;
#elif PAWN_CELL_SIZE==32
  typedef uint32_t  ucell;
  typedef int32_t   cell;
#elif PAWN_CELL_SIZE==64
  typedef uint64_t  ucell;
  typedef int64_t   cell;
#else
  #error Unsupported cell size (PAWN_CELL_SIZE)
#endif

With this:

#if !defined PAWN_CELL_SIZE
  #define PAWN_CELL_SIZE 32     /* by default, use 32-bit cells */
#endif
#if PAWN_CELL_SIZE==32
  typedef uint32_t  ucell;
  typedef int32_t   cell;
#else
  #error Unsupported cell size (PAWN_CELL_SIZE)
#endif

And now you will need to comment the line 493 of file source/amx/amx.c

assert_static(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */

It should look like this:

  if (amx->sysreq_d!=0) {
    /* at the point of the call, the CIP pseudo-register points directly
     * behind the SYSREQ instruction and its parameter(s)
     */
....
    // <--- HERE IS IT: I COMMENTED IT TO AVOID ERRORS ON COMPILATION ---->
    // assert_static(sizeof(f)<=sizeof(cell)); /* function pointer must fit in a cell */
    // <--- --------------------------------------------------------- ---->
....

Once you comment this line, you will be able to compile, type this in your terminal:

cmake ../source/compiler -DCMAKE_C_FLAGS=-m64 -DCMAKE_BUILD_TYPE=Release
make
  1. Once compiled, copy the files to your pawno folder, and enjoy!
  • build/pawncc
  • build/pawndisasm
  • build/libpawnc.dylib

By doing this, I was able to code and compile my scripts on M1.

Workspace Information:

  • Compiler version: Pawn compiler 3.10.10
  • Command line arguments provided (or sampctl version):
./pawno/pawncc /path/to/your/gamemodes/MyGame.pwn -Dgamemodes '-;+' '-(+' '-d3' '-Z' '-i/path/to/your/includes'
  • Operating System: macOS Ventura 13 on Apple M1

soknifedev avatar Sep 03 '23 05:09 soknifedev

Can you please upload this build? I don‘t have space for Xcode. Thank you!

halfbloodprince27 avatar Dec 06 '23 19:12 halfbloodprince27

This is not an issue, is just a tip to build the compiler and run it on Apple M1 Chip computers.

@soknifedev Thanks, it compiled perfectly. Haven't actually tested the resulting amx file yet though.

Can you please upload this build? I don‘t have space for Xcode. Thank you!

@halfbloodprince27 You shouldn't trust builds from strangers, but here you go:

https://woet.me/m1-pawncc-3.10.10.zip (master branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-3.10.11.zip (dev branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-openmp.zip (Branch_minor-tweaks branch of openmultiplayer/compiler repo)

Woet avatar Dec 13 '23 01:12 Woet

This is not an issue, is just a tip to build the compiler and run it on Apple M1 Chip computers.

@soknifedev Thanks, it compiled perfectly. Haven't actually tested the resulting amx file yet though.

Can you please upload this build? I don‘t have space for Xcode. Thank you!

@halfbloodprince27 You shouldn't trust builds from strangers, but here you go:

https://woet.me/m1-pawncc-3.10.10.zip (master branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-3.10.11.zip (dev branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-openmp.zip (Branch_minor-tweaks branch of openmultiplayer/compiler repo)

Have you tested the resulting AMX file? I didn't have time to do so when I compiled the pawncc executable (even today 😅).

I would like to know if it works as expected; I made these changes based on a comment from Y_Less on another issue

soknifedev avatar Jan 16 '24 14:01 soknifedev

This is cool, however for some reason the instance is not able to find the header files required to compile successfully. I have Xcode installed.

Pawn compiler 3.10.10 Copyright (c) 1997-2006, ITB CompuPhase

test.pwn(1) : fatal error 100: cannot read from file: "stdio.h"

Compilation aborted.

1 Error.

REFUZIION avatar Jan 16 '24 16:01 REFUZIION

You're just deleting an assertion, without actually fixing the problem it is there to fix. Check the open.mp fork for better 32/64 bit compatibility. Right now, your natives will just crash, you haven't got it working on 64-bit systems, you've just disabled the errors.

Y-Less avatar Jan 17 '24 21:01 Y-Less

This is not an issue, is just a tip to build the compiler and run it on Apple M1 Chip computers.

@soknifedev Thanks, it compiled perfectly. Haven't actually tested the resulting amx file yet though.

Can you please upload this build? I don‘t have space for Xcode. Thank you!

@halfbloodprince27 You shouldn't trust builds from strangers, but here you go:

https://woet.me/m1-pawncc-3.10.10.zip (master branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-3.10.11.zip (dev branch of pawn-lang/compiler repo) https://woet.me/m1-pawncc-openmp.zip (Branch_minor-tweaks branch of openmultiplayer/compiler repo)

update you link for pawncc 3.10.10 please.

RiccardoMorreti avatar Mar 05 '24 14:03 RiccardoMorreti