Skip to content

Commit bed9c0f

Browse files
Merge pull request MonoGame#58 from AristurtleDev/fix/mac-build-steps
Fix/mac build steps
2 parents 42d8436 + e21507f commit bed9c0f

File tree

1 file changed

+58
-30
lines changed
  • articles/tutorials/building_2d_games/25_packaging_game

1 file changed

+58
-30
lines changed

articles/tutorials/building_2d_games/25_packaging_game/index.md

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -153,28 +153,34 @@ To create this structure, from the same terminal window:
153153
> [!NOTE]
154154
> The `mkdir -p` command creates directories including any necessary parent directories. The `-p` flag ensures all intermediate directories are created without error if they do not exist yet.
155155

156-
2. Combine the Intel (x64) and Apple Silicon (arm64) builds into a `universal binary`. To do this, execute the following commands:
156+
2. Copy all files from the Intel (x64) build to the MacOS directory. This ensures all the required dependencies are included. To do this, execute the following command:
157157

158158
```sh
159-
lipo -create bin/Release/net8.0/osx-arm64/publish/DungeonSlime bin/Release/net8.0/osx-x64/publish/DungeonSlime -output bin/Release/DungeonSlime.app/Contents/MacOS/DungeonSlime
159+
cp -R bin/Release/net8.0/osx-x64/publish/* bin/Release/DungeonSlime.app/Contents/MacOS/
160160
```
161161

162162
> [!NOTE]
163-
> The `lipo` command is a macOS utility that works with multi-architecture binaries. Here, it combines the Intel (x64) and Apple Silicon (arm64) executables into a single "universal binary" that can run natively on both Apple Silicon and Intel processor based Macs.
163+
> This copies all files from the publish directory, including the executable, all dependent `.dll` files, and the `Content` directory that contains your game assets.
164+
165+
3. Replace the executable with a universal binary that works on both Intel and Apple Silicon Macs. To do this, execute the following command:
166+
167+
```sh
168+
lipo -create bin/Release/net8.0/osx-arm64/publish/DungeonSlime bin/Release/net8.0/osx-x64/publish/DungeonSlime -output bin/Release/DungeonSlime.app/Contents/MacOS/DungeonSlime
169+
```
164170

165171
> [!NOTE]
166-
> Note, make sure to the change in folder from `net8.0` to `net9.0` if it is appropriate.
172+
> The `lipo` command is a macOS utility that works with multi-architecture binaries. Here, it combines the Intel (x64) and Apple Silicon (arm64) executables into a single "universal binary" that can run natively on both Apple Silicon and Intel processor based Macs.
167173

168-
3. Next, copy the your content files to the expected location within the application bundle structure. To do this, execute the following commands:
174+
4. Move the Content directory from the MacOS directory to the Resources directory, following macOS application bundle conventions. To do this, execute the following command:
169175

170176
```sh
171-
cp -R bin/Release/net8.0/Content bin/Release/DungeonSlime.app/Contents/Resources/Content
177+
mv bin/Release/DungeonSlime.app/Contents/MacOS/Content bin/Release/DungeonSlime.app/Contents/Resources/
172178
```
173179

174180
> [!NOTE]
175-
> The `cp -R` command copies files recursively, meaning it will copy the entire directory structure. The `-R` flag ensures all subdirectories and their contents are copied.
181+
> This moves the `Content` directory to the expected location for resources in a macOS application bundles.
176182

177-
4. Create a new file called `Info.plist` in the `Contents` directory of the application bundle with the following command:
183+
5. Create a new file called *Info.plist* in the *Contents* directory of the application bundle with the following command:
178184

179185
```sh
180186
touch bin/Release/DungeonSlime.app/Contents/Info.plist
@@ -183,7 +189,7 @@ To create this structure, from the same terminal window:
183189
> [!NOTE]
184190
> The `touch` command creates an empty file if it does not exist or updates the modification time if it does exist. We are using it here to create a blank file that we will populate with content in the next step.
185191

186-
5. Open the `Info.plist` file you just created in a text editor and add the following content to the file and save it.
192+
6. Open the *Info.plist* file you just created in a text editor and add the following content to the file and save it.
187193

188194
[!code-xml[](./snippets/info.plist?highlight=8,10,12,16,30)]
189195

@@ -209,30 +215,52 @@ To create this structure, from the same terminal window:
209215
>
210216
> For more information on the `Info.plist` manifest file, refer to the [About Info.plist Keys and Values](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html) Apple Developer documentation.
211217

212-
6. Next, create the application bundle `.icns` icon file. To do this, execute the following commands:
213218

214-
```sh
215-
mkdir -p bin/Release/DungeonSlime.iconset
216-
sips -z 16 16 Icon.png --out bin/Release/DungeonSlime.iconset/icon_16x16.png
217-
sips -z 32 32 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
218-
sips -z 32 32 Icon.png --out bin/Release/DungeonSlime.iconset/icon_32x32.png
219-
sips -z 64 64 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
220-
sips -z 128 128 Icon.png --out bin/Release/DungeonSlime.iconset/icon_128x128.png
221-
sips -z 256 256 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
222-
sips -z 256 256 Icon.png --out bin/Release/DungeonSlime.iconset/icon_256x256.png
223-
sips -z 512 512 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
224-
sips -z 512 512 Icon.png --out bin/Release/DungeonSlime.iconset/icon_512x512.png
225-
sips -z 1024 1024 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
226-
iconutil -c icns bin/Release/DungeonSlime.iconset --output bin/Release/DungeonSlime.app/Contents/Resources/DungeonSlime.icns
227-
```
219+
7. Next, create the application bundle *.icns* icon file. To do this, perform the following:
228220

229-
> [!NOTE]
230-
> These commands create a macOS icon file (`.icns`) with multiple resolutions:
231-
> - `sips` (Scriptable Image Processing System) resizes the source image to create different icon sizes.
232-
> - Each size is necessary for different display scenarios in macOS (Dock, Finder, etc.).
233-
> - The `iconutil` command then compiles these images into a single `.icns` file that macOS recognizes as an application icon.
221+
1. First, you will need a `.png` file that can be used to create the icon set for the final `.icns` output. If you already have a `.png` icon for your game, ensure it is in the root of the main project directory and is named `Icon.png`. If you do not have one already prepared, you can use the `Icon.bmp` that was generated in the root of the main project directory when you initially created the project. However, it will need to be converted to a `.png` first. To do this, execute the following command:
222+
223+
```sh
224+
sips -s format png Icon.bmp --out Icon.png
225+
```
226+
227+
> [!NOTE]
228+
> `sips` (Scriptable Image Processing System) is a command line tool in macOS for image manipulation. Here we are using it to convert a `.bmp` to a `.png`. In a moment, we will also use it to resize the `.png` into different icon sizes required for the application bundle.
229+
230+
2. Next, create a directory that we can output each of the generated `.png` icon files to for the icon set. Execute the following command:
231+
232+
```sh
233+
mkdir -p bin/Release/DungeonSlime.iconset
234+
```
235+
236+
3. Now we use the `sips` command to generate the icon for each size required for a mac app bundle. Each size generated is neccessary for different display scenarios in macOS (Dock, Finder, etc.). To do this, execute the following commands:
237+
238+
```sh
239+
sips -z 16 16 Icon.png --out bin/Release/DungeonSlime.iconset/icon_16x16.png
240+
sips -z 32 32 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
241+
sips -z 32 32 Icon.png --out bin/Release/DungeonSlime.iconset/icon_32x32.png
242+
sips -z 64 64 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
243+
sips -z 128 128 Icon.png --out bin/Release/DungeonSlime.iconset/icon_128x128.png
244+
sips -z 256 256 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
245+
sips -z 256 256 Icon.png --out bin/Release/DungeonSlime.iconset/icon_256x256.png
246+
sips -z 512 512 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
247+
sips -z 512 512 Icon.png --out bin/Release/DungeonSlime.iconset/icon_512x512.png
248+
sips -z 1024 1024 Icon.png --out bin/Release/DungeonSlime.iconset/[email protected]
249+
```
250+
251+
4. Finally, combine all of the generated icons for the icon set into a `.icns` file. To do this, execute the following:
252+
253+
```sh
254+
iconutil -c icns bin/Release/DungeonSlime.iconset --output bin/Release/DungeonSlime.app/Contents/Resources/DungeonSlime.icns
255+
```
256+
257+
> [!NOTE]
258+
> `iconutil` is a command line tool in macOS used to convert icon sets into a single high-resolution `.icns` file.
259+
260+
> [!TIP]
261+
> After creating the `.icns` file using the above command, if you open the folder in Finder with `DungeonSlime.app` and it shows a blank square as the icon instead of the one you just created, right-click on `DungeonSlime.app` and choose `Get Info` from the context menu. This will force it to do a refresh and show the icon properly. After doing this, if the icon still does not show, then you need to double check that the `CFBundleIconFile` value in the `Info.plist` is named **exactly** the same as the `.icns` file that was created (minus the extension).
234262

235-
7. Set executable permissions for the game executable. To do this, execute the following command:
263+
8. Set executable permissions for the game executable. To do this, execute the following command:
236264

237265
```sh
238266
chmod +x bin/Release/DungeonSlime.app/Contents/MacOS/DungeonSlime

0 commit comments

Comments
 (0)