JetBrains / RiderSourceCodeAccess

Plugin for UE4 to user Rider for Unreal Engine as code editor
Apache License 2.0
112 stars 21 forks source link

-ForceUseSystemCompiler flag doesn't work with Rider projectfiles. #8

Open Zerophase opened 3 years ago

Zerophase commented 3 years ago

Running ./GenerateProjectFiles.sh -Rider -ForceUseSystemCompiler causes

WARNING: Exception while generating include data for Target:BenchmarkTool, Platform: Linux, Configuration: Debug

Breaks towards the bottom of WriteProjectFile in RiderProjectFile.cs.

arcolight commented 3 years ago

@Zerophase, Can you give us some info about linux distribution you use and UE version? Also there should be exception message in the log just after the "WARNING: ....". Can you, please, post it here?

Zerophase commented 3 years ago

@arcolight Arch Linux. UE 4.26.2

GenerateProjectFiles.log

arcolight commented 3 years ago

@Zerophase I have reproduced your error on my system only when I moved shipped clang SDK from its location in UnrealEngine/Engine/Extras/ThirdPartyNotUE/SDKs.

Do you have shipped clang SDK in this location? It should be installed with Setup.sh.

Are you trying to force UE to use your system compiler instead of SDK? SDK clang preferred over system even when ForceUseSystemCompiler flag specified:

Engine/Source/Programs/UnrealBuildTool/Platform/Linux/LinuxToolChain.cs:

public LinuxToolChain(string InArchitecture, LinuxPlatformSDK InSDK, bool InPreservePSYM = false, LinuxToolChainOptions InOptions = LinuxToolChainOptions.None)
    : this(UnrealTargetPlatform.Linux, InArchitecture, InSDK, InPreservePSYM, InOptions)
{
// ...
    bool bForceUseSystemCompiler = PlatformSDK.ForceUseSystemCompiler();
// ...
    if (bForceUseSystemCompiler)
    {
// ...
        // use native linux toolchain
        ClangPath = LinuxCommon.WhichClang(); // <=== find clang
        GCCPath = LinuxCommon.WhichGcc();
        ArPath = LinuxCommon.Which("ar");
        LlvmArPath = LinuxCommon.Which("llvm-ar");
        RanlibPath = LinuxCommon.Which("ranlib");
        StripPath = LinuxCommon.Which("strip");
        ObjcopyPath = LinuxCommon.Which("objcopy");

        // if clang is available, zero out gcc (@todo: support runtime switching?)
        if (!String.IsNullOrEmpty(ClangPath)) // <=== clang preferred over gcc
        {
            GCCPath = null;
        }
// ...
    }
// ...

Engine/Source/Programs/UnrealBuildTool/Platform/Linux/LinuxCommon.cs:

public static string WhichClang()
{
    string InternalSDKPath = LinuxPlatformSDK.GetInternalSDKPath();
    if (!String.IsNullOrEmpty(InternalSDKPath)) // <=== shipped clang preferred over system
    {
        return Path.Combine(InternalSDKPath, "bin", "clang++");
    }

    string[] ClangNames = { "clang++", "clang++-7.0", "clang++-6.0" };
    string ClangPath;
    foreach (string ClangName in ClangNames)
    {
        ClangPath = Which(ClangName);
        if (!String.IsNullOrEmpty(ClangPath))
        {
            return ClangPath;
        }
    }

    return null;
}

How to fix this issue now:

in file Engine/Source/Programs/UnrealBuildTool/ProjectFiles/Rider/RiderProjectFile.cs:

private void ExportEnvironmentToJson(UEBuildTarget Target, JsonWriter Writer)
{
// ... 
        var InternalSdkPath = LinuxPlatformSDK.GetInternalSDKPath();
    if (InternalSdkPath != null) // <=== Add check
    {
        Writer.WriteValue(Path.Combine(InternalSdkPath, "include"));
        Writer.WriteValue(Path.Combine(InternalSdkPath, "usr/include"));
        Writer.WriteValue(Path.Combine(InternalSdkPath, "lib/clang/" + Version + "/include/"));
    }
Zerophase commented 3 years ago

I maintain the latest clang support, and Unreal in the aur. I have LINUX_MULTIARCH_ROOT set to /usr/sbin, and that stops the sdk from installing. It saves a decent amount of space. I do have a pull request up for further system compiler support by the engine. Thanks for the quick fix.

arcolight commented 3 years ago

I've created PR in UE with this fix, it should be in next release, I suppose.

SaladinAyyub commented 3 years ago

@Zerophase I am "shuriken" from the AUR. We can also have this as patch file in the AUR in a case where -if the PR doesn't land in the Unreal Engine release and Rider for Unreal Engine (Linux) gets released.

SaladinAyyub commented 3 years ago

This issue can be closed as this PR has been merged https://github.com/EpicGames/UnrealEngine/pull/7957 Also now on Arch Linux the Unreal Bundled clang has become the default and system clang has been removed from the PKGBUILD due to issues with clang 12. But the fix will allow to use system clang on other distros as well. Thanks @arcolight