Skip to content

Commit 20a78a8

Browse files
committed
Build self contained single file output
1 parent 5c6b3f9 commit 20a78a8

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

build.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,34 @@ func Build() error {
2323
if err != nil {
2424
return err
2525
}
26+
data.OS = strings.ReplaceAll(data.OS, "macos", "osx")
27+
data.OS = strings.ReplaceAll(data.OS, "windows", "win")
28+
data.Arch = strings.ReplaceAll(data.Arch, "arm32", "arm")
2629

2730
switch config.Type {
2831
case "client":
29-
return buildClient(config.Game, data.Output, config.URL)
32+
return buildClient(config.Game, data.Output, config.URL, data.OS, data.Arch)
3033
default:
3134
return fmt.Errorf("Unknown project type: %s", config.Type)
3235
}
3336
}
3437

35-
func buildClient(gameName, output, url string) error {
38+
func buildClient(gameName, output, url, os, arch string) error {
3639
cli.BeginLoading("Building...")
3740
gameDir := toPascal(gameName)
3841
err := replaceInFile(filepath.Join(gameDir, "Game.cs"), "throw new InvalidOperationException(\"The CG_GAME_URL environment variable must be set.\")", "return \""+url+"\"")
3942
if err != nil {
4043
return err
4144
}
4245

43-
args := []string{"build", "--nologo", "--self-contained", "--configuration", "Release"}
44-
os := getOS()
45-
arch := getArch()
46-
if os != "" && arch != "" {
47-
args = append(args, "--runtime", os+"-"+arch)
48-
} else {
49-
args = append(args, "--use-current-runtime")
46+
args := []string{"publish", "--nologo", "--configuration", "Release", "--self-contained"}
47+
if os == "current" {
48+
os = getOS()
5049
}
50+
if arch == "current" {
51+
arch = getArch()
52+
}
53+
args = append(args, "--runtime", os+"-"+arch)
5154
if output != "" {
5255
args = append(args, "--output", output)
5356
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/Bananenpro/cli v0.3.0
7-
github.com/code-game-project/go-utils v0.2.11
7+
github.com/code-game-project/go-utils v0.2.13
88
)
99

1010
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63n
66
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
77
github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
88
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
9-
github.com/code-game-project/go-utils v0.2.11 h1:PhAD+6cPacBuAFcfBEV5oHhzo0R9/N48ZGSpziKOKCE=
10-
github.com/code-game-project/go-utils v0.2.11/go.mod h1:/ws9iYkZCnZvS9g2aqdxKwSnU5AEeI7SE1mbB+x4ggg=
9+
github.com/code-game-project/go-utils v0.2.13 h1:Am5raDGXHPywKH6VtKFEvG7rx6GbaJ8G0z6eHGnufX4=
10+
github.com/code-game-project/go-utils v0.2.13/go.mod h1:/ws9iYkZCnZvS9g2aqdxKwSnU5AEeI7SE1mbB+x4ggg=
1111
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
1212
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
1313
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func Run() error {
3333
}
3434

3535
func runClient(url string, args []string) error {
36-
cmdArgs := []string{"run", "--"}
36+
cmdArgs := []string{"run", "--no-self-contained", "--"}
3737
cmdArgs = append(cmdArgs, args...)
3838

3939
env := []string{"CG_GAME_URL=" + url}

templates/new/client/csproj.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
<RootNamespace>{{.ProjectName}}</RootNamespace>
77
<ImplicitUsings>enable</ImplicitUsings>
88
<Nullable>enable</Nullable>
9+
<PublishSingleFile>true</PublishSingleFile>
10+
<PublishReadyToRun>true</PublishReadyToRun>
11+
<PublishTrimmed>true</PublishTrimmed>
12+
</PropertyGroup>
13+
14+
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
15+
<DebugSymbols>false</DebugSymbols>
16+
<DebugType>None</DebugType>
17+
<Optimize>true</Optimize>
18+
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
919
</PropertyGroup>
1020

1121
</Project>

0 commit comments

Comments
 (0)