Building on macOS

Apple M1

As of this writing (August 18, 2022), Perforce doesn’t provide any official builds for M1. However, p4api (the C library that backs their products and p4python) does have M1 support.

To build for M1, you will need to build p4api and p4python from scratch.

<aside> 💡 Or download these builds, which is probably easier:

https://downloads.reviewboard.org/ports/p4python/

</aside>

Building p4api for M1

  1. Install jam and openssl from brew:

    $ brew install jam
    $ brew install openssl
    
  2. Figure out and set your OS version value.

You will need to specify your macOS version in these steps wherever you see ${OSVER}. This is in XXYY form. For example, macOS 11.01 would be 1101. macOS 12.1 would be 1201. (I think — this is pretty roughly correlated).

(Note: It’s not necessarily that clear-cut. macOS 12.5 seems to need 1203.)

Set this for future examples and for the build process:

```bash
$ export OSVER=1203
```
  1. Create your directory hierarchy and set up your SSL symlinks. For these examples, we’ll use ~/src/p4 as the root. You’ll want:

    $ mkdir ~/src/p4
    $ cd ~/src/p4
    $ mkdir p4-bin
    $ cd p4-bin
    $ ln -s `brew --prefix [email protected]`/lib lib.macosx${OSVER}arm64
    $ ln -s `brew --prefix [email protected]`/include inc.macosx${OSVER}arm64
    
  2. Find the latest rX.Y/bin.tools/p4source.tgz file in their FTP server and extract it.

As of the above date, the latest version is at http://filehost.perforce.com/perforce/r22.1/bin.tools/p4source.tgz.

<aside>
💡 If the latest version changes, please update the instructions here and below!

</aside>

```bash
$ cd ~/src/p4
$ wget <http://filehost.perforce.com/perforce/r22.1/bin.tools/p4source.tgz>
$ tar -xvf p4source.tgz
$ cd p4source-2022.1.2305383
```
  1. Patch Jamrules if on macOS 12+:

The version listed above does not explicitly support macOS 12 or higher. You’ll need to apply a version of this patch.

[Jamrules.patch](<https://s3-us-west-2.amazonaws.com/secure.notion-static.com/6c46317b-0464-4496-be2e-edb42c54ce53/Jamrules.patch>)

NOTE: Tweak that accordingly for your macOS version!
  1. Run jam with all the right parameters:

    $ cd ~/src/p4/p4source-*
    
    # You may have to update CLANGVER. Check clang --version.
    $ jam -sCLANGVER=13.1 -sOS=MACOSX -sOSVER=${OSVER} -sOSPLAT=ARM64
    
    $ cd api
    $ jam -sCLANGVER=13.1 -sOS=MACOSX -sOSVER=${OSVER} -sOSPLAT=ARM64 \\
          p4api.tgz
    
    

If all went well, this should have built everything without errors. The result should be a ../p4-bin/bin.macosx${OSVER}arm64/p4api.tgz file, and a versioned directory with the extracted contents in the same directory. Make note of this directory.