Skip to content

Commit

Permalink
Dockerfile update, linux scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Leinnan committed May 15, 2024
1 parent 4081e06 commit 2159a8c
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 157 deletions.
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM ghcr.io/epicgames/unreal-engine:dev-5.3.2 as builder

USER ue4
# use --build-arg BUILD_TYPE=-server in docker build to set it to be server build
ARG BUILD_TYPE
ARG BUILD_TYPE=" "

# by default it passes all maps, you can pass value `--build-arg MAP_ARG=-map=DefaultMap+BeamBackendTests` to override it
ARG MAP_ARG=-allmaps
Expand All @@ -12,13 +12,18 @@ ARG SERVER_CONFIG=Shipping
# Copy your Unreal project files into the Docker image
COPY --chown=ue4 . /home/ue4/project

RUN /home/ue4/UnrealEngine/Engine/Build/BatchFiles/Linux/GenerateProjectFiles.sh -projectfiles -project=/home/ue4/project/BeamableUnreal.uproject -game -rocket -progress
RUN chmod +x /home/ue4/project/clean_project.sh
RUN /home/ue4/project/clean_project.sh
RUN /home/ue4/UnrealEngine/Engine/Binaries/ThirdParty/DotNet/6.0.302/linux/dotnet /home/ue4/UnrealEngine/Engine/Binaries/DotNET/UnrealBuildTool/UnrealBuildTool.dll -ProjectFiles -UsePrecompiled -Game "/home/ue4/project/BeamableUnreal.uproject"
# RUN chmod +x /home/ue4/project/init_repo.sh
# RUN /home/ue4/project/init_repo.sh
RUN /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -project=/home/ue4/project/BeamableUnreal.uproject \
-utf8output \
-platform=Linux \
-clientconfig=$CLIENT_CONFIG \
-serverconfig=$SERVER_CONFIG \
$BUILD_TYPE \
-noP4 -nodebuginfo $MAP_ARG \
-cook -build -stage -prereqs -pak -archive \
-archivedirectory=/home/ue4/PackagedProject
-cook -build -pak -archive \
-stage -prereqs \
-archivedirectory=/home/ue4/PackagedProject || cat /home/ue4/Library/Logs/Unre*gine/LocalBuildLogs/UBT-.txt && false
149 changes: 0 additions & 149 deletions Plugins/BeamableCore/Source/BeamableCore/BeamableCore.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,153 +54,4 @@ public BeamableCore(ReadOnlyTargetRules Target) : base(Target)
}
);
}
}

public static class BeamableModuleUtils
{
public struct OssConfig
{
public bool IsEnabled;
public bool HooksEnabled;
public string HookSubsystemImplementation;
public string HookSubsystemIncludePath;
public string[] AdditionalHookModules;
}


public class BeamableAdditionalData
{
public string[] OssAdditionalModules = Array.Empty<string>();
}


public static void ConfigureEditor(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreBlueprintNodes",
"BeamableCoreRuntime",
"BeamableCoreEditor",

"Json",
"JsonUtilities",
});
}

public static void ConfigureServer(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreRuntime",

"Json",
"JsonUtilities",
});
}

public static void ConfigureGame(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreRuntime",

"Json",
"JsonUtilities",
});
}


/// <summary>
/// To be used in Target.cs files to add objects to <see cref="TargetRules.AdditionalData"/> in order to be used by various Build.cs files.
/// </summary>
public static T GetOrAddAdditionalData<T>(TargetRules TargetRules) where T : class, new()
{
TargetRules.AdditionalData ??= new Dictionary<Type, object>();

var dict = TargetRules.AdditionalData as Dictionary<Type, object>;
dict!.TryAdd(typeof(T), new T());
return dict[typeof(T)] as T;
}

/// <summary>
/// To be used in Build.cs files to read objects added to the <see cref="TargetRules.AdditionalData"/> by <see cref="GetOrAddAdditionalData{T}"/>.
/// </summary>
public static T GetAdditionalData<T>(this ReadOnlyTargetRules TargetRules) where T : class, new()
{
if (TargetRules.AdditionalData is Dictionary<Type, object> dictionary)
{
if (dictionary.TryGetValue(typeof(T), out var data))
return data as T;

throw new Exception(
$"Failed to find an additional data with the given type {typeof(T).Name}.\n" +
"Make sure you call GetOrAddAdditionalData<T> from your Target.cs file passing in the correct Type.\n");
}

throw new Exception(
"Using beamable requires the AdditionalData to be a Dictionary of Type/Object.\n" +
"We provide a utility function that allows you to add your own additional data next to beamable's own BeamableAdditionalData.\n" +
"We do this because the Beamable plugin needs some additional data but we didn't want to lock you out of passing in your own things.");
}


/// <summary>
/// Configures the Beamable SDK to work with UE's Online Subsystem stuff.
/// </summary>
private static void ConfigOnlineSubsystem(TargetRules TargetRules, OssConfig OssConfig, BeamableAdditionalData AdditionalData)
{
// Don't do anything to configure OSS if its not enabled
if (!OssConfig.IsEnabled) return;

// Include the OnlineSubsystem modules in the target.
TargetRules.ExtraModuleNames.AddRange(new[]
{
"OnlineSubsystem",
"OnlineSubsystemUtils",
"OnlineSubsystemBeamable"
});

// If we are building the editor, we also add the OnlineSubsystemBeamableBp module (which is where your BeamFlow nodes for Microservices live when OSS is enabled)
if (TargetRules.bBuildEditor)
{
TargetRules.ExtraModuleNames.AddRange(new[]
{
"OnlineSubsystemBeamableBp" // TODO: Make sure this module exists before doing this.
});
}

// Add the ENABLE OSS define so that the BeamableCore plugins can declare some utilities for when it is working with OSS
TargetRules.ProjectDefinitions.Add("BEAM_ENABLE_BEAMABLE_OSS=1");

// If OSS Hooks are enabled, the customer can pass in the Hook entry point implementation and we'll auto-configure it for them.
if (OssConfig.HooksEnabled)
{
TargetRules.ProjectDefinitions.Add("BEAM_ENABLE_OSS_HOOKS=1");
TargetRules.ProjectDefinitions.Add($"BEAM_OSS_SUBSYSTEM_IMPLEMENTATION={OssConfig.HookSubsystemImplementation}");
TargetRules.ProjectDefinitions.Add($"BEAM_OSS_SUBSYSTEM_INCLUDE=BEAM_STRINGIFY({OssConfig.HookSubsystemIncludePath})");

// Pass down, to the OnlineSubsystemBeamable plugin, a list of Module names that it'll also depend on
AdditionalData.OssAdditionalModules = OssConfig.AdditionalHookModules;
}
}

private static void AddUtilityMacros(TargetRules TargetRules)
{
TargetRules.ProjectDefinitions.Add("BEAM_STRINGIFY(X)=#X");
}
}
150 changes: 150 additions & 0 deletions Source/BeamableUnreal.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class BeamableUnrealTarget : TargetRules

public BeamableUnrealTarget(TargetInfo Target) : base(Target)
{
bOverrideBuildEnvironment = true;
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.Latest;
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
Expand Down Expand Up @@ -116,4 +117,153 @@ public static void ConfigureIfHathoraDemo(TargetRules TargetRules, string beamPr
}
}
}
}

public static class BeamableModuleUtils
{
public struct OssConfig
{
public bool IsEnabled;
public bool HooksEnabled;
public string HookSubsystemImplementation;
public string HookSubsystemIncludePath;
public string[] AdditionalHookModules;
}


public class BeamableAdditionalData
{
public string[] OssAdditionalModules = Array.Empty<string>();
}


public static void ConfigureEditor(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreBlueprintNodes",
"BeamableCoreRuntime",
"BeamableCoreEditor",

"Json",
"JsonUtilities",
});
}

public static void ConfigureServer(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreRuntime",

"Json",
"JsonUtilities",
});
}

public static void ConfigureGame(TargetRules TargetRules, OssConfig OssConfig)
{
var additionalData = GetOrAddAdditionalData<BeamableAdditionalData>(TargetRules);
AddUtilityMacros(TargetRules);
ConfigOnlineSubsystem(TargetRules, OssConfig, additionalData);

TargetRules.ExtraModuleNames.AddRange(new[]
{
"BeamableCore",
"BeamableCoreRuntime",

"Json",
"JsonUtilities",
});
}


/// <summary>
/// To be used in Target.cs files to add objects to <see cref="TargetRules.AdditionalData"/> in order to be used by various Build.cs files.
/// </summary>
public static T GetOrAddAdditionalData<T>(TargetRules TargetRules) where T : class, new()
{
TargetRules.AdditionalData ??= new Dictionary<Type, object>();

var dict = TargetRules.AdditionalData as Dictionary<Type, object>;
dict!.TryAdd(typeof(T), new T());
return dict[typeof(T)] as T;
}

/// <summary>
/// To be used in Build.cs files to read objects added to the <see cref="TargetRules.AdditionalData"/> by <see cref="GetOrAddAdditionalData{T}"/>.
/// </summary>
public static T GetAdditionalData<T>(this ReadOnlyTargetRules TargetRules) where T : class, new()
{
if (TargetRules.AdditionalData is Dictionary<Type, object> dictionary)
{
if (dictionary.TryGetValue(typeof(T), out var data))
return data as T;

throw new Exception(
$"Failed to find an additional data with the given type {typeof(T).Name}.\n" +
"Make sure you call GetOrAddAdditionalData<T> from your Target.cs file passing in the correct Type.\n");
}

throw new Exception(
"Using beamable requires the AdditionalData to be a Dictionary of Type/Object.\n" +
"We provide a utility function that allows you to add your own additional data next to beamable's own BeamableAdditionalData.\n" +
"We do this because the Beamable plugin needs some additional data but we didn't want to lock you out of passing in your own things.");
}


/// <summary>
/// Configures the Beamable SDK to work with UE's Online Subsystem stuff.
/// </summary>
private static void ConfigOnlineSubsystem(TargetRules TargetRules, OssConfig OssConfig, BeamableAdditionalData AdditionalData)
{
// Don't do anything to configure OSS if its not enabled
if (!OssConfig.IsEnabled) return;

// Include the OnlineSubsystem modules in the target.
TargetRules.ExtraModuleNames.AddRange(new[]
{
"OnlineSubsystem",
"OnlineSubsystemUtils",
"OnlineSubsystemBeamable"
});

// If we are building the editor, we also add the OnlineSubsystemBeamableBp module (which is where your BeamFlow nodes for Microservices live when OSS is enabled)
if (TargetRules.bBuildEditor)
{
TargetRules.ExtraModuleNames.AddRange(new[]
{
"OnlineSubsystemBeamableBp" // TODO: Make sure this module exists before doing this.
});
}

// Add the ENABLE OSS define so that the BeamableCore plugins can declare some utilities for when it is working with OSS
TargetRules.ProjectDefinitions.Add("BEAM_ENABLE_BEAMABLE_OSS=1");

// If OSS Hooks are enabled, the customer can pass in the Hook entry point implementation and we'll auto-configure it for them.
if (OssConfig.HooksEnabled)
{
TargetRules.ProjectDefinitions.Add("BEAM_ENABLE_OSS_HOOKS=1");
TargetRules.ProjectDefinitions.Add($"BEAM_OSS_SUBSYSTEM_IMPLEMENTATION={OssConfig.HookSubsystemImplementation}");
TargetRules.ProjectDefinitions.Add($"BEAM_OSS_SUBSYSTEM_INCLUDE=BEAM_STRINGIFY({OssConfig.HookSubsystemIncludePath})");

// Pass down, to the OnlineSubsystemBeamable plugin, a list of Module names that it'll also depend on
AdditionalData.OssAdditionalModules = OssConfig.AdditionalHookModules;
}
}

private static void AddUtilityMacros(TargetRules TargetRules)
{
TargetRules.ProjectDefinitions.Add("BEAM_STRINGIFY(X)=#X");
}
}
2 changes: 1 addition & 1 deletion clean_project.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
echo * Clean Unreal Engine Project *
echo.
echo Cleaning your project, please wait...
FOR /d /r %%d IN ("Binaries","Build","Intermediate","Saved","DerivedDataCache","PackagedProject") DO @IF EXIST "%%d" rd /s /q "%%d"
FOR /d /r %%d IN ("Build","Intermediate","Saved","DerivedDataCache","PackagedProject") DO @IF EXIST "%%d" rd /s /q "%%d"
del *.sln
echo.
echo Your project cleaned perfectly, you can generate Visual Studio project files now.
Expand Down
18 changes: 18 additions & 0 deletions clean_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set +v
BASEDIR=$(dirname "$0")
echo "$BASEDIR"
cd $BASEDIR
echo "* Clean Unreal Engine Project *"
echo ""
echo "Cleaning your project, please wait..."
# Use find to locate directories and remove them
for dir in Build Intermediate Saved DerivedDataCache PackagedProject; do
find . -type d -name "$dir" -exec rm -rf {} +
done
# Delete all .sln files in the current directory
rm -f *.sln

echo ""
echo "Your project cleaned perfectly, you can generate Visual Studio project files now."
4 changes: 2 additions & 2 deletions docker_build.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
docker pull ghcr.io/epicgames/unreal-engine:dev-5.3.2

IF "%1"=="server" (
docker build --build-arg BUILD_TYPE=-server --build-arg MAP_ARG=-map=DefaultMap+BeamBackendTests --progress plain -t unrealrunner .
docker build --build-arg BUILD_TYPE=-dedicatedserver --build-arg MAP_ARG=-allmaps --progress plain -t unrealrunner .
) ELSE (
docker build --build-arg MAP_ARG=-map=DefaultMap+BeamBackendTests --progress plain -t unrealrunner .
)
docker run --name unreal_container -d beamable-unreal-client:latest
docker run --name unreal_container -d unrealrunner:latest
docker cp unreal_container:/home/ue4/PackagedProject .
docker stop unreal_container
docker rm unreal_container

0 comments on commit 2159a8c

Please sign in to comment.