Skip to content

Commit 5a26d12

Browse files
committed
Merge branch 'topic/1150-support-architectures-other-than-amd64-x86_64' into 'master'
Support more architectures and platforms in VS Code See merge request eng/ide/ada_language_server!1257
2 parents 2875743 + fb7ba34 commit 5a26d12

File tree

8 files changed

+124
-27
lines changed

8 files changed

+124
-27
lines changed

.github/workflows/build-binaries.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,23 @@ function fix_rpath ()
9393
install_name_tool -add_rpath @executable_path $1
9494
}
9595

96+
# Get architecture and platform information from node.
97+
NODE_ARCH=$(node -e "console.log(process.arch)")
98+
NODE_PLATFORM=$(node -e "console.log(process.platform)")
99+
ALS_EXEC_DIR=integration/vscode/ada/$NODE_ARCH/$NODE_PLATFORM
100+
96101
if [ $RUNNER_OS = macOS ]; then
97-
cp -v -f /usr/local/opt/gmp/lib/libgmp.10.dylib integration/vscode/ada/darwin/
98-
fix_rpath integration/vscode/ada/darwin/ada_language_server
102+
cp -v -f /usr/local/opt/gmp/lib/libgmp.10.dylib $ALS_EXEC_DIR
103+
fix_rpath $ALS_EXEC_DIR/ada_language_server
99104
fi
100105

101106
if [ "$DEBUG" != "debug" ]; then
102-
# Here it's better to match an exact extension rather than mathing
103-
# ada_language_server* because when running locally, the latter could match
104-
# ada_language_server.dSYM from a previous run if it exists.
107+
cd $ALS_EXEC_DIR
105108
if [ $RUNNER_OS = Windows ]; then
106-
ALS=`ls integration/vscode/ada/*/ada_language_server.exe`
109+
ALS=ada_language_server.exe
107110
else
108-
ALS=`ls integration/vscode/ada/*/ada_language_server`
111+
ALS=ada_language_server
109112
fi
110-
cd `dirname $ALS`
111-
ALS=`basename ${ALS}`
112113
if [ $RUNNER_OS = macOS ]; then
113114
# On macOS using objcopy from binutils to strip debug symbols to a
114115
# separate file doesn't work. Namely, the last step `objcopy

.github/workflows/build-binaries.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,12 @@ jobs:
107107
uses: actions/upload-artifact@v3
108108
with:
109109
name: als-${{ runner.os }}-${{ matrix.debug }}
110-
path: integration/vscode/ada/[ldw]*/*
110+
# We know that only one of the following entries will match on a given
111+
# run, so we use globs here to try to avoid warnings on unmatched
112+
# entries
113+
path: |
114+
integration/vscode/ada/arm*
115+
integration/vscode/ada/x64*
111116
package:
112117
if: ${{ github.event_name == 'push' }}
113118
needs: build

.github/workflows/pack-binaries.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ function make_change_log()
1818
}
1919

2020
chmod -R -v +x als-*-$DEBUG
21-
for X in Linux macOS Windows ; do mv -v -f als-$X-$DEBUG/* integration/vscode/ada/; done
22-
rm -rf -v integration/vscode/ada/{linux,darwin,win32}/*.{debug,dSYM}
21+
22+
for X in Linux macOS Windows ; do
23+
rsync -rva als-$X-$DEBUG/ integration/vscode/ada/
24+
done
25+
26+
# VS Code is supported on arm, arm64 and x64 so we only consider those
27+
# architectures
28+
rm -rf -v integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}/*.{debug,dSYM}
29+
2330
pushd integration/vscode/ada
2431
sed -i -e "/version/s/[0-9][0-9.]*/$TAG/" package.json
2532
[ -z "$DEBUG" ] || sed -i -e '/^ "name"/s/ada/ada-debug/' \
@@ -38,4 +45,4 @@ vsce package || true
3845
popd
3946
mv -v integration/vscode/ada/*.vsix .
4047
git checkout integration/vscode/ada/package.json
41-
rm -rf integration/vscode/ada/{linux,darwin,win32}
48+
rm -rf integration/vscode/ada/{arm,arm64,x64}/{linux,darwin,win32}

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,16 @@ ENV/
9797
# Expected testsuite output
9898
testsuite/.als/inout.txt
9999

100-
# Generated integration packages
100+
# Locations of ALS executable in VS Code extension. VS Code is supported on arm,
101+
# arm64 and x64 so we only consider those architectures.
102+
integration/vscode/ada/arm/
103+
integration/vscode/ada/arm64/
104+
integration/vscode/ada/x64/
105+
106+
# Previous locations of ALS executable in VS Code extension
101107
integration/vscode/ada/linux/
108+
integration/vscode/ada/win32/
109+
integration/vscode/ada/darwin/
102110

103111
# GNAT Studio clangd options
104112
.clang-format

.gitlab-ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ build_and_test:
9696
--failure-exit-code 1
9797
--xunit-output $CI_PROJECT_DIR/vscode_xunit_output.xml
9898
$VSCODE_BUILD_SPACE/results/new/ || FAILED=true
99+
# Temporarily use the original JUnit report until e3-testsuite-report is
100+
# fixed. See it/e3-testsuite#7.
101+
- cp -f $VSCODE_BUILD_SPACE/results/mocha/test-results.xml $CI_PROJECT_DIR/vscode_xunit_output.xml
99102
# Include Anod logs
100103
- cp -r $ANOD_DEFAULT_SANDBOX_DIR/log $CI_PROJECT_DIR/anod-logs
101104
- echo -e "\e[0Ksection_end:`date +%s`:prepare_artifacts\r\e[0K"

Makefile

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,27 @@ COVERAGE=
3434
COVERAGE_INSTR=gnatcov instrument --level stmt $(LIBRARY_FLAGS) \
3535
--dump-trigger=atexit --no-subprojects
3636

37+
ifeq (,$(shell which node))
38+
# Node is not available so do not define node-related variables
39+
else
40+
# Set NODE variable as an indicator that node is available
41+
NODE=node
42+
# Obtain architecture and platform from the node executable. This information
43+
# is used to deposit the ALS executable at the location expected by the VS
44+
# Code Ada extension.
45+
NODE_ARCH=$(shell node -e "console.log(process.arch)")
46+
NODE_PLATFORM=$(shell node -e "console.log(process.platform)")
47+
endif
48+
3749
# Target platform as nodejs reports it
3850
ifeq ($(OS),Windows_NT)
39-
PLATFORM=win32
4051
PYTHON=python.exe
4152
EXE=.exe
4253
else
4354
UNAME_S := $(shell uname -s)
4455
ifeq ($(UNAME_S),Linux)
45-
PLATFORM=linux
4656
OS=unix
47-
endif
48-
ifeq ($(UNAME_S),Darwin)
49-
PLATFORM=darwin
57+
else ifeq ($(UNAME_S),Darwin)
5058
OS=osx
5159
endif
5260
PYTHON=python3
@@ -80,8 +88,10 @@ all: coverage-instrument
8088
$(GPRBUILD) -P gnat/codec_test.gpr -p $(COVERAGE_BUILD_FLAGS)
8189
$(GPRBUILD) -P gnat/lsp_client.gpr -p $(COVERAGE_BUILD_FLAGS) \
8290
-XVERSION=$(VERSION)
83-
mkdir -p integration/vscode/ada/$(PLATFORM)
84-
cp -f $(ALS)$(EXE) integration/vscode/ada/$(PLATFORM)
91+
ifdef NODE
92+
mkdir -p integration/vscode/ada/$(NODE_ARCH)/$(NODE_PLATFORM)
93+
cp -f $(ALS)$(EXE) integration/vscode/ada/$(NODE_ARCH)/$(NODE_PLATFORM)
94+
endif
8595

8696
generate:
8797
python scripts/generate.py
@@ -119,7 +129,7 @@ clean:
119129
-$(GPRCLEAN) -P gnat/lsp_server.gpr $(LIBRARY_FLAGS)
120130
-$(GPRCLEAN) -P gnat/tester.gpr $(LIBRARY_FLAGS)
121131
-$(GPRCLEAN) -P gnat/codec_test.gpr $(LIBRARY_FLAGS)
122-
-rm -rf integration/vscode/ada/$(PLATFORM)
132+
-rm -rf integration/vscode/ada/$(NODE_ARCH)/$(NODE_PLATFORM)
123133

124134
vscode:
125135
ifneq ($(npm_config_offline),true)
@@ -151,4 +161,4 @@ check: all
151161
${CODEC_TEST} < testsuite/codecs/index.txt
152162

153163
deploy: check
154-
integration/$(USER)/deploy.sh $(PLATFORM)
164+
integration/$(USER)/deploy.sh $(NODE_PLATFORM)

integration/vscode/ada/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"darwin"
3939
],
4040
"cpu": [
41+
"arm64",
4142
"x64"
4243
],
4344
"keywords": [

integration/vscode/ada/src/extension.ts

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { alsCommandExecutor } from './alsExecuteCommand';
3131
import GnatTaskProvider, { getEnclosingSymbol } from './gnatTaskProvider';
3232
import GprTaskProvider from './gprTaskProvider';
3333
import { getEvaluatedCustomEnv } from './helpers';
34+
import { existsSync } from 'fs';
3435

3536
export let contextClients: ContextClients;
3637
export let mainLogChannel: vscode.OutputChannel;
@@ -114,6 +115,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
114115
mainLogChannel = vscode.window.createOutputChannel('Ada Extension');
115116
mainLogChannel.appendLine('Starting Ada extension');
116117

118+
assertSupportedEnvironments();
119+
117120
context.subscriptions.push(
118121
vscode.commands.registerCommand('ada.showExtensionOutput', () => mainLogChannel.show())
119122
);
@@ -182,8 +185,38 @@ function createClient(
182185
extra: string[],
183186
pattern: string
184187
) {
185-
let serverModule = context.asAbsolutePath(process.platform + '/ada_language_server');
186-
if (process.env.ALS) serverModule = process.env.ALS;
188+
let serverExecPath: string;
189+
190+
if (process.arch == 'arm64' && process.platform == 'darwin') {
191+
// On arm64 darwin use the x64 darwin executable thanks to Apple Rosetta.
192+
serverExecPath = context.asAbsolutePath(`x64/darwin/ada_language_server`);
193+
} else {
194+
serverExecPath = context.asAbsolutePath(
195+
`${process.arch}/${process.platform}/ada_language_server`
196+
);
197+
}
198+
199+
// If the ALS environment variable is specified, use it as the path of the
200+
// server executable.
201+
if (process.env.ALS) {
202+
serverExecPath = process.env.ALS;
203+
if (!existsSync(serverExecPath)) {
204+
logErrorAndThrow(
205+
`The Ada language server given in the ALS environment ` +
206+
`variable does not exist: ${serverExecPath}`
207+
);
208+
}
209+
} else {
210+
if (!existsSync(serverExecPath)) {
211+
logErrorAndThrow(
212+
`This installation of the Ada extension does not have the Ada ` +
213+
`language server for your architecture (${process.arch}) ` +
214+
`and platform (${process.platform}) ` +
215+
`at the expected location: ${serverExecPath}`
216+
);
217+
}
218+
}
219+
187220
// The debug options for the server
188221
// let debugOptions = { execArgv: [] };
189222
// If the extension is launched in debug mode then the debug server options are used
@@ -203,8 +236,8 @@ function createClient(
203236

204237
// Options to control the server
205238
const serverOptions: ServerOptions = {
206-
run: { command: serverModule, args: extra },
207-
debug: { command: serverModule, args: extra },
239+
run: { command: serverExecPath, args: extra },
240+
debug: { command: serverExecPath, args: extra },
208241
};
209242

210243
// Options to control the language client
@@ -352,3 +385,32 @@ async function checkSrcDirectories(alsClient: LanguageClient) {
352385
});
353386
}
354387
}
388+
389+
function assertSupportedEnvironments() {
390+
type Env = {
391+
arch: 'arm' | 'arm64' | 'x64';
392+
platform: 'win32' | 'linux' | 'darwin';
393+
};
394+
const supportedEnvs: Env[] = [
395+
{ arch: 'x64', platform: 'linux' },
396+
{ arch: 'x64', platform: 'win32' },
397+
{ arch: 'x64', platform: 'darwin' },
398+
{ arch: 'arm64', platform: 'darwin' },
399+
];
400+
401+
if (
402+
!supportedEnvs.some((val) => {
403+
return val.arch == process.arch && val.platform == process.platform;
404+
})
405+
) {
406+
const msg =
407+
`The Ada extension is not supported on ` +
408+
`architecture '${process.arch}' and platform '${process.platform}'`;
409+
logErrorAndThrow(msg);
410+
}
411+
}
412+
413+
function logErrorAndThrow(msg: string) {
414+
mainLogChannel.appendLine('[Error] ' + msg);
415+
throw new Error(msg);
416+
}

0 commit comments

Comments
 (0)