Skip to content

Commit 88181cf

Browse files
authored
Merge pull request #77 from roginvs/add_builtin_sslc_compiler
Add built-in compiler for Fallout2 .ssl files
2 parents 7e763a7 + 472a0dd commit 88181cf

File tree

11 files changed

+195
-12
lines changed

11 files changed

+195
-12
lines changed

.vscodeignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
# Rollup native bindings
1515
!server/node_modules/@rollup/rollup*/**
1616

17+
!server/node_modules/sslc-emscripten-noderawfs/**
18+
1719
!preview/package.json
1820
!preview/out/index.html
1921
!preview/out/index.css

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ BGforge MLS is a VScode extension adding support for [Star-Trek Scripting Langua
2020
- [Hovers](#fallout-highlighting-and-hovers)
2121
- [Error reporting](#error-reporting)
2222
- Signature help, diagnostics, docstrings, etc. See the [forum](https://forums.bgforge.net/viewforum.php?f=35).
23+
- Embedded cross-platform .ssl compiler (check `falloutSSL.useBuiltInCompiler` option)
2324

2425
### Installation
2526

@@ -48,3 +49,5 @@ BGforge MLS is a VScode extension adding support for [Star-Trek Scripting Langua
4849
#### Error reporting
4950

5051
![error reporting example](docs/error_reporting.png)
52+
53+

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.3.0
4+
5+
Add built-in .ssl compiler
6+
37
## 2.2.6
48

59
Cosmetic: fixed double dot in tmp filenames, introduced in 2.2.5.

docs/settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ _([How to change settings in VScode](https://code.visualstudio.com/docs/getstart
1717
### Fallout SSL
1818

1919
- `bgforge.falloutSSL.compilePath`: Path to compile.exe from sfall modders pack. Alternatively, you can add compile.exe to system PATH and leave default here.
20+
- `bgforge.falloutSSL.useBuiltInCompiler`: Use built-in compiler instead of external compile.exe
2021
- `bgforge.falloutSSL.compileOptions`: Compilation options for compile.exe from sfall modders pack.
2122
- `bgforge.falloutSSL.outputDirectory`: Where to put the compiled Fallout SSL scripts, absolute path. Default is to put compiled scripts next to the source file. You'll probably want to set this to `data/scripts` of your Fallout 2 game directory.
2223
- `bgforge.falloutSSL.headersDirectory`: Path to an additional directory with Fallout headers to scan for defines.

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "bgforge-mls",
33
"displayName": "BGforge MLS",
44
"description": "BGforge multilanguage server",
5-
"version": "2.2.6",
5+
"version": "2.3.0",
66
"author": "BGforge",
77
"repository": {
88
"type": "git",
@@ -344,10 +344,15 @@
344344
"type": "object",
345345
"title": "BGforge MLS",
346346
"properties": {
347+
"bgforge.falloutSSL.useBuiltInCompiler": {
348+
"type": "boolean",
349+
"default": false,
350+
"description": "Use built-in compiler instead of external compile.exe"
351+
},
347352
"bgforge.falloutSSL.compilePath": {
348353
"type": "string",
349354
"default": "wine ~/bin/compile",
350-
"description": "Path to compile.exe from sfall modders pack. Alternatively, you can add compile.exe to system PATH and leave default here."
355+
"description": "Path to compile.exe from sfall modders pack. Alternatively, you can add compile.exe to system PATH and leave default here. Ignored if 'Use built-in compiler' is enabled."
351356
},
352357
"bgforge.falloutSSL.compileOptions": {
353358
"type": "string",
@@ -443,4 +448,4 @@
443448
"esbuild"
444449
]
445450
}
446-
}
451+
}

server/package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "bgforge-mls-server",
33
"description": "BGforge multilanguage server",
4-
"version": "2.2.6",
4+
"version": "2.3.0",
55
"author": "BGforge",
66
"license": "SEE LICENSE IN LICENSE.txt",
77
"engines": {
88
"vscode": "^1.69.2",
99
"node": "*"
1010
},
11+
"scripts": {},
1112
"repository": {
1213
"type": "git",
1314
"url": "https://github.com/BGforgeNet/VScode-BGforge-MLS/server"
@@ -17,6 +18,7 @@
1718
"@supercharge/promise-pool": "^2.3.2",
1819
"fast-glob": "^3.2.12",
1920
"rollup": "^4.30.1",
21+
"sslc-emscripten-noderawfs": "https://github.com/sfall-team/sslc/releases/download/2025-06-18-01-40-04/wasm-emscripten-node-noderawfs.tar.gz",
2022
"strip-literal": "^1.0.0",
2123
"ts-morph": "^24.0.0",
2224
"tslib": "^2.8.1",
@@ -35,4 +37,4 @@
3537
"@types/vscode": "^1.69.1",
3638
"@vscode/test-electron": "^2.2.1"
3739
}
38-
}
40+
}

server/src/compile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function compile(uri: string, langId: string, interactive = false,
5959

6060
if (falloutLanguages.includes(langId)) {
6161
clearDiagnostics(uri);
62-
fallout.compile(uri, settings.falloutSSL, interactive, text);
62+
await fallout.compile(uri, settings.falloutSSL, interactive, text);
6363
return;
6464
}
6565

server/src/fallout.ts

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { Edge, Node } from "./preview";
2424
import { connection, documents } from "./server";
2525
import { SSLsettings } from "./settings";
2626
import * as signature from "./signature";
27+
import { ssl_compile as ssl_builtin_compiler } from "./sslc/ssl_compiler";
2728

2829
interface FalloutHeaderData {
2930
macros: Macros;
@@ -36,7 +37,7 @@ interface Procedure {
3637
detail: string;
3738
jsdoc?: jsdoc.JSdoc;
3839
}
39-
interface Procedures extends Array<Procedure> { }
40+
interface Procedures extends Array<Procedure> {}
4041
interface Macro {
4142
label: string;
4243
detail: string;
@@ -45,7 +46,7 @@ interface Macro {
4546
firstline: string;
4647
jsdoc?: jsdoc.JSdoc;
4748
}
48-
interface Macros extends Array<Macro> { }
49+
interface Macros extends Array<Macro> {}
4950

5051
const tooltipLangId = "fallout-ssl-tooltip";
5152
const sslExt = ".ssl";
@@ -594,7 +595,32 @@ function sendDiagnostics(uri: string, outputText: string, tmpUri: string) {
594595
sendParseResult(parseResult, uri, tmpUri);
595596
}
596597

597-
export function compile(uri: string, sslSettings: SSLsettings, interactive = false, text: string) {
598+
let successfullCompilerPath: string | null = null;
599+
async function checkExternalCompiler(compilePath: string) {
600+
if (compilePath === successfullCompilerPath) {
601+
// Check compiler only once
602+
return Promise.resolve(true);
603+
}
604+
605+
return new Promise<boolean>((resolve) => {
606+
cp.exec(`${compilePath} --version`, (err) => {
607+
conlog(`Compiler check '${compilePath} --version' err=${err}`);
608+
if (err) {
609+
resolve(false);
610+
} else {
611+
successfullCompilerPath = compilePath;
612+
resolve(true);
613+
}
614+
});
615+
});
616+
}
617+
618+
export async function compile(
619+
uri: string,
620+
sslSettings: SSLsettings,
621+
interactive = false,
622+
text: string,
623+
) {
598624
const filepath = uriToPath(uri);
599625
const cwdTo = path.dirname(filepath);
600626
// tmp file has to be in the same dir, because includes can be relative or absolute
@@ -618,6 +644,46 @@ export function compile(uri: string, sslSettings: SSLsettings, interactive = fal
618644
conlog(`compiling ${baseName}...`);
619645

620646
fs.writeFileSync(tmpPath, text);
647+
648+
let useBuiltInCompiler = sslSettings.useBuiltInCompiler;
649+
650+
if (!useBuiltInCompiler && !(await checkExternalCompiler(sslSettings.compilePath))) {
651+
const response = await connection.window.showErrorMessage(
652+
`Failed to run '${sslSettings.compilePath}'! Use built-in compiler this time?`,
653+
{ title: "Yes", id: "yes" },
654+
{ title: "No", id: "no" },
655+
);
656+
if (response?.id === "yes") {
657+
useBuiltInCompiler = true;
658+
}
659+
}
660+
661+
if (useBuiltInCompiler) {
662+
const { stdout, returnCode } = await ssl_builtin_compiler({
663+
interactive,
664+
cwd: cwdTo,
665+
inputFileName: tmpName,
666+
outputFileName: dstPath,
667+
options: sslSettings.compileOptions,
668+
headersDir: sslSettings.headersDirectory,
669+
});
670+
if (returnCode === 0) {
671+
if (interactive) {
672+
connection.window.showInformationMessage(`Successfully compiled ${baseName}.`);
673+
}
674+
} else {
675+
if (interactive) {
676+
connection.window.showErrorMessage(`Failed to compile ${baseName}!`);
677+
}
678+
}
679+
sendDiagnostics(uri, stdout, tmpUri);
680+
// sometimes it gets deleted due to async runs?
681+
if (fs.existsSync(tmpPath)) {
682+
fs.unlinkSync(tmpPath);
683+
}
684+
return;
685+
}
686+
621687
conlog(`${compileCmd} "${tmpName}" -o "${dstPath}"`);
622688
cp.exec(
623689
`${compileCmd} "${tmpName}" -o "${dstPath}"`,

server/src/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { conlog } from "./common";
55

66
export interface SSLsettings {
77
compilePath: string;
8+
useBuiltInCompiler: boolean;
89
compileOptions: string;
910
outputDirectory: string;
1011
headersDirectory: string;
@@ -29,6 +30,7 @@ export interface MLSsettings {
2930
export const defaultSettings: MLSsettings = {
3031
falloutSSL: {
3132
compilePath: "compile",
33+
useBuiltInCompiler: false,
3234
compileOptions: "-q -p -l -O2 -d -s -n",
3335
outputDirectory: "",
3436
headersDirectory: "",

0 commit comments

Comments
 (0)