From 19eaec336df5b43a7ab22fd63c06ad22b1fe7b89 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Mon, 4 Jul 2022 23:06:09 +0300 Subject: [PATCH 1/5] Use better linkers to improve linking times on Linux --- .../Platforms/Unix/UnixToolchain.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs index eb4c8f183..373dde534 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs @@ -61,6 +61,11 @@ namespace Flax.Build.Platforms /// protected string LdPath; + /// + /// The type of the linker. + /// + protected string LdKind; + /// /// The clang tool version. /// @@ -91,7 +96,19 @@ namespace Flax.Build.Platforms RanlibPath = UnixPlatform.Which("ranlib"); StripPath = UnixPlatform.Which("strip"); ObjcopyPath = UnixPlatform.Which("objcopy"); - LdPath = UnixPlatform.Which("ld"); + + LdPath = UnixPlatform.Which("ld.lld"); + LdKind = "lld"; + if (LdPath == null) + { + LdPath = UnixPlatform.Which("ld.gold"); + LdKind = "gold"; + } + if (LdPath == null) + { + LdPath = UnixPlatform.Which("ld"); + LdKind = null; + } } else { @@ -478,6 +495,9 @@ namespace Flax.Build.Platforms // TODO: linkEnvironment.LinkTimeCodeGeneration // TODO: linkEnvironment.Optimization // TODO: linkEnvironment.UseIncrementalLinking + + if (!string.IsNullOrEmpty(LdKind)) + args.Add(string.Format("-fuse-ld={0}", LdKind)); } SetupLinkFilesArgs(graph, options, args, outputFilePath); From 591b45d2e8f7d9d411512325dcbc67c7866f330b Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 5 Jul 2022 05:24:02 +0300 Subject: [PATCH 2/5] Fix linking errors with other linkers --- Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs index 373dde534..53e20db63 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using System.Text.RegularExpressions; using Flax.Build.Graph; using Flax.Build.NativeCpp; @@ -556,9 +557,10 @@ namespace Flax.Build.Platforms } } - // Input files + // Input files (link static libraries last) task.PrerequisiteFiles.AddRange(linkEnvironment.InputFiles); - foreach (var file in linkEnvironment.InputFiles) + foreach (var file in linkEnvironment.InputFiles.Where(x => !x.EndsWith(".a")) + .Concat(linkEnvironment.InputFiles.Where(x => x.EndsWith(".a")))) { args.Add(string.Format("\"{0}\"", file.Replace('\\', '/'))); } From c51a9231602c12d0ad4c1591d5b62ddbff2d4886 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 5 Feb 2023 13:38:29 +0200 Subject: [PATCH 3/5] Only pass --copy-dt-needed-entries with GNU linker --- Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs | 3 ++- Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs index 9bc9aab33..96ef470e4 100644 --- a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs @@ -75,7 +75,8 @@ namespace Flax.Build.Platforms args.Add("-Wl,-rpath,\"\\$ORIGIN\""); //args.Add("-Wl,--as-needed"); - args.Add("-Wl,--copy-dt-needed-entries"); + if (LdKind == "bfd") + args.Add("-Wl,--copy-dt-needed-entries"); args.Add("-Wl,--hash-style=gnu"); //args.Add("-Wl,--build-id"); diff --git a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs index 53e20db63..6bbb8707f 100644 --- a/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Unix/UnixToolchain.cs @@ -107,8 +107,8 @@ namespace Flax.Build.Platforms } if (LdPath == null) { - LdPath = UnixPlatform.Which("ld"); - LdKind = null; + LdPath = UnixPlatform.Which("ld"); // ld.bfd + LdKind = "bfd"; } } else From 533a6576b87ee4272cb9056176f28dfd3234031f Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 7 Feb 2023 22:11:24 +0200 Subject: [PATCH 4/5] Link against zlib --- Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs index 96ef470e4..352d6158e 100644 --- a/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Linux/LinuxToolchain.cs @@ -96,6 +96,7 @@ namespace Flax.Build.Platforms args.Add("-pthread"); args.Add("-ldl"); args.Add("-lrt"); + args.Add("-lz"); // Link X11 args.Add("-L/usr/X11R6/lib"); From ca81ee39675da6cbb232cdbd36cc848a1a22b4e0 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Tue, 7 Feb 2023 22:27:31 +0200 Subject: [PATCH 5/5] Update Linux build instructions --- README.md | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4ef31c91c..3cbcfb6fe 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Flax Visual Studio extension provides better programming workflow, C# scripts de * Install Windows 8.1 SDK or newer (via Visual Studio Installer) * Install Microsoft Visual C++ 2015 v140 toolset or newer (via Visual Studio Installer) * Install .Net Framework 4.5.2 SDK/Targeting Pack (via Visual Studio Installer) +* Install Git with LFS * Clone repo (with LFS) * Run **GenerateProjectFiles.bat** * Open `Flax.sln` and set solution configuration to **Editor.Development** and solution platform to **Win64** @@ -48,12 +49,23 @@ Flax Visual Studio extension provides better programming workflow, C# scripts de ## Linux * Install Visual Studio Code -* Install Mono ([https://www.mono-project.com/download/stable](https://www.mono-project.com/download/stable)) -* Install Vulkan SDK ([https://vulkan.lunarg.com/](https://vulkan.lunarg.com/)) +* Install Mono + * Ubuntu: see the instructions here: ([https://www.mono-project.com/download/stable](https://www.mono-project.com/download/stable)) + * Arch: `sudo pacman -S mono` +* Install Vulkan SDK + * Ubuntu: see the instructions here: ([https://vulkan.lunarg.com/](https://vulkan.lunarg.com/)) + * Arch: `sudo pacman -S spirv-tools vulkan-headers vulkan-tools vulkan-validation-layers` * Install Git with LFS -* Install requried packages: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev nuget autoconf libogg-dev automake build-essential gettext cmake python libtool libtool-bin libpulse-dev libasound2-dev libjack-dev portaudio19-dev` -* Install compiler `sudo apt-get install clang lldb lld` (Clang 6 or newer) -* Clone repo (with LFS) + * Ubuntu: `sudo apt-get install git git-lfs` + * Arch: `sudo pacman -S git git-lfs` + * `git-lfs install` +* Install the required packages: + * Ubuntu: `sudo apt-get install libx11-dev libxcursor-dev libxinerama-dev zlib1g-dev` + * Arch: `sudo pacman -S base-devel libx11 libxcursor libxinerama zlib` +* Install Clang compiler (version 6 or later): + * Ubuntu: `sudo apt-get install clang lldb lld` + * Arch: `sudo pacman -S clang lldb lld` +* Clone the repository (with LFS) * Run `./GenerateProjectFiles.sh` * Open workspace with Visual Code * Build and run (configuration and task named `Flax|Editor.Linux.Development|x64`)