DigitalLogicSimCommunity/Digital-Logic-Sim-CE

Make this repo a homebrew "tap"

AriSweedler opened this issue · 9 comments

To build this from source requires unity installed. https://josusb.com/blog/build-unity-cmd/

That doesn't seem so hard to do, but I've never done this before. I'm going to use this issue to track the work I do. I hope I don't bother people with notifications :)

Since building from source requires such a large tool, I should have my "tap" ship a "bottle" (pre-built binary), just like you guys already do here. Instead of letting the user build from source. We can try and allow users to build from source later.

In homebrew, a "bottle" is a pre-built versioned package definition placed into homebrew's data directory (instead of building from upstream sources). https://docs.brew.sh/Bottles

I want to build form source to make a bottle, and I'll keep all of my scripts in the repo: https://github.com/AriSweedler/homebrew-Digital-Logic-Sim-CE

Unfortunately, for a user who wants to build this repo, it won't be as simple as cloning THAT repo and running a script inside of it. A user who wants to build this repo will have to install unity. I have used unity hub to install the necessary version of unity.

Here is the command that my build script invokes:

/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -PROJECT_PATH /Users/ari/Desktop/Digital-Logic-Sim-CE -buildOSXUniversalPlayer /Users/ari/Desktop/build-dlsce/dlsce.app -logFile /Users/ari/Desktop/build-dlsce/build_log.txt

I get errors of the following style:

Assets/Scripts/Save System/FolderLoader.cs(1,7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)

So clearly I'm missing something. Opening up the file where I saw this error I see

using Newtonsoft.Json;

Which is just an attempt to import the Newtonsoft Json library: https://docs.unity3d.com/2019.4/Documentation/Manual/com.unity.nuget.newtonsoft-json.html

There's gotta be a way to download a library (or does Unity call them plugins) such that my build script sees them. Maybe it's already downloaded and I just need to let my compiler know where to look.

It looks like Unity may use what npm uses - a package.json: https://docs.unity3d.com/Manual/upm-manifestPkg.html

But this project is missing it. If that's the case, I should just be able to make one and then unity will use that to download the right plugins?

Trying to use the unity package manager to create my package.json manifest. Looking at https://docs.unity3d.com/Manual/upm-ui-install.html I learned how to open the unity package manager (lol I really am n00b @ this, never ran unity before this). From there, I was able to add a package by name: com.unity.nuget.newtonsoft-json. I don't know which version I need but I'm sure I'll find out soon enough if stuff breaks :)

Success! I was able to build once I imported the package. It changes than was necessary, though, so I'm going to work on making those changes as minimal as possible.

Oh no. After reverting the changes to the manifest.json file, the build still succeeded. That means there's a globally installed package somewhere on my machine that - even if it's not mentioned in the manifest - is being used. What the heck! Checking the build logs, looks like it's actually just a build cache:

[Package Manager] Restoring resolved packages state from cache
    com.unity.nuget.newtonsoft-json@3.0.2 (location: /Users/ari/Desktop/Digital-Logic-Sim-CE/Library/PackageCache/com.unity.nuget.newtonsoft-json@3.0.2)

Hmm. Another thing I see is that the diff between cached packages and resolved packages is 1 package:

    com.unity.services.core@1.6.0 (location: /Users/ari/Desktop/Digital-Logic-Sim-CE/Library/PackageCache/com.unity.services.core@1.6.0)

And then of course the packages that I accidentally upgraded by not pinning the version of NewtonSoft to the right version. I'm going to clear my cache, try to get a compile error again, then use older versions of NewtonSoft until I don't make any unnecessary changes to the manifest. Maybe I'll try to find the version of the NewtonSoft lib in source code first though

Hmmm. I'm now seeing that NewtonSoft was already totally in the manifest:

+    "com.unity.services.core": {
+      "version": "1.6.0",
+      "depth": 1,
+      "source": "registry",
+      "dependencies": {
+        "com.unity.modules.unitywebrequest": "1.0.0",
+        "com.unity.nuget.newtonsoft-json": "3.0.2",
+        "com.unity.modules.androidjni": "1.0.0"
+      },
+      "url": "https://packages.unity.com"
+    },

just... nested. Not sure what's going on here. But even after clearing the cache, the build succeeded. I need to know why it failed the first time so that my build script can account for this. This is proving to be less than straightforward to track down, though.

At the time of me doing all of this, unity's latest update is 2021.3.18f1. I'm not using that to build this, though, ofc. I'm using 2021.3.14f1, as the project expects.

❯ sudo find /Applications/Unity/Hub/Editor/2021.3.14f1 -iname "*newtonsoft*"
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/PlaybackEngines/MacStandaloneSupport/Newtonsoft.Json.dll
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Managed/Newtonsoft.Json.dll
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Tools/BuildPipeline/Newtonsoft.Json.dll
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/com.unity.template.3d-8.1.3/Bee/artifacts/mvdfrm/Unity.Plastic.Newtonsoft.Json.dll_D733C885B96B6E8A.mvfrm
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/com.unity.template.universal-2d-1.1.3/Bee/artifacts/mvdfrm/Unity.Plastic.Newtonsoft.Json.dll_D733C885B96B6E8A.mvfrm
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Resources/PackageManager/ProjectTemplates/libcache/com.unity.template.2d-6.1.1/Bee/artifacts/mvdfrm/Unity.Plastic.Newtonsoft.Json.dll_D733C885B96B6E8A.mvfrm
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Resources/PackageManager/Editor/com.unity.nuget.newtonsoft-json-3.0.2.tgz
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/il2cpp/build/deploy/Newtonsoft.Json.dll
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/Frameworks/UnityLicensingClient.app/Contents/Resources/Newtonsoft.Json.dll

I'm confused as to what I'm seeing lol. I know what a shared object ELF file is, and that a .dll is like this but for windows & PE I know .NET is like java in that it can run anywhere - so I think that file is wrong and that these .dlls are actually fine to run on my mac. I mean obviously it's fine, the filepath has MacStandaloneSupport in the name and besides I just ran the app.

❯ file /Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/PlaybackEngines/MacStandaloneSupport/Newtonsoft.Json.dll
/Applications/Unity/Hub/Editor/2021.3.14f1/Unity.app/Contents/PlaybackEngines/MacStandaloneSupport/Newtonsoft.Json.dll: PE32 executable (DLL) (console) Intel 80386 Mono/.Net assembly, for MS Windows