Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build rust python finder for CI and produce a package #23465

Merged
merged 14 commits into from
May 22, 2024
27 changes: 19 additions & 8 deletions .github/actions/build-vsix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ inputs:
artifact_name:
description: 'Name to give the artifact containing the VSIX'
required: true
cargo_target:
description: 'Cargo build target for the native build'
required: true
vsix_target:
description: 'vsix build target for the native build'
required: true

runs:
using: 'composite'
Expand Down Expand Up @@ -47,27 +53,32 @@ runs:
run: nox --session install_python_libs
shell: bash

- name: Add Rustup target
run: rustup target add ${{ inputs.cargo_target }}
shell: bash

- name: Build Native Binaries
run: nox --session native_build
shell: bash
env:
CARGO_TARGET: ${{ inputs.cargo_target }}

- name: Run npm ci
run: npm ci --prefer-offline
shell: bash

# Use the GITHUB_RUN_ID environment variable to update the build number.
# GITHUB_RUN_ID is a unique number for each run within a repository.
# This number does not change if you re-run the workflow run.
- name: Update extension build number
run: npm run updateBuildNumber -- --buildNumber $GITHUB_RUN_ID
shell: bash

- name: Update optional extension dependencies
run: npm run addExtensionPackDependencies
shell: bash

- name: Build Webpack
run: |
npx gulp clean
npx gulp prePublishBundle
shell: bash

- name: Build VSIX
run: npm run package
run: npx vsce package --target ${{ inputs.vsix_target }} --out ms-python-insiders.vsix --pre-release
shell: bash

- name: Rename VSIX
Expand Down
49 changes: 43 additions & 6 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ env:
PYTHON_VERSION: '3.10' # YML treats 3.10 the number as 3.1, so quotes around 3.10
MOCHA_REPORTER_JUNIT: true # Use the mocha-multi-reporters and send output to both console (spec) and JUnit (mocha-junit-reporter). Also enables a reporter which exits the process running the tests if it haven't already.
ARTIFACT_NAME_VSIX: ms-python-insiders-vsix
VSIX_NAME: ms-python-insiders.vsix
TEST_RESULTS_DIRECTORY: .
# Force a path with spaces and to test extension works in these scenarios
# Unicode characters are causing 2.7 failures so skip that for now.
Expand All @@ -22,7 +21,38 @@ env:
jobs:
build-vsix:
name: Create VSIX
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
vsix-target: win32-x64
- os: windows-latest
target: aarch64-pc-windows-msvc
vsix-target: win32-arm64
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
vsix-target: linux-x64
# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# vsix-target: linux-arm64
# - os: ubuntu-latest
# target: arm-unknown-linux-gnueabihf
# vsix-target: linux-armhf
- os: macos-latest
target: x86_64-apple-darwin
vsix-target: darwin-x64
- os: macos-14
target: aarch64-apple-darwin
vsix-target: darwin-arm64
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
vsix-target: alpine-x64
# - os: ubuntu-latest
# target: aarch64-unknown-linux-musl
# vsix-target: alpine-arm64
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -31,8 +61,10 @@ jobs:
uses: ./.github/actions/build-vsix
with:
node_version: ${{ env.NODE_VERSION}}
vsix_name: ${{ env.VSIX_NAME }}
artifact_name: ${{ env.ARTIFACT_NAME_VSIX }}
vsix_name: 'ms-python-insiders-${{ matrix.vsix-target }}.vsix'
artifact_name: '${{ env.ARTIFACT_NAME_VSIX }}-${{ matrix.vsix-target }}'
cargo_target: ${{ matrix.target }}
vsix_target: ${{ matrix.vsix-target }}

lint:
name: Lint
Expand Down Expand Up @@ -345,7 +377,12 @@ jobs:
matrix:
# We're not running CI on macOS for now because it's one less matrix entry to lower the number of runners used,
# macOS runners are expensive, and we assume that Ubuntu is enough to cover the UNIX case.
os: [ubuntu-latest, windows-latest]
include:
- os: windows-latest
vsix-target: win32-x64
- os: ubuntu-latest
vsix-target: linux-x64

steps:
# Need the source to have the tests available.
- name: Checkout
Expand All @@ -355,7 +392,7 @@ jobs:
uses: ./.github/actions/smoke-tests
with:
node_version: ${{ env.NODE_VERSION }}
artifact_name: ${{ env.ARTIFACT_NAME_VSIX }}
artifact_name: '${{ env.ARTIFACT_NAME_VSIX }}-${{ matrix.vsix-target }}'

### Coverage run
coverage:
Expand Down
46 changes: 36 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import os
import pathlib
import nox
import shutil
import sys
import sysconfig


@nox.session()
Expand Down Expand Up @@ -45,26 +47,50 @@ def install_python_libs(session: nox.Session):


@nox.session()
def native_build(session:nox.Session):
def native_build(session: nox.Session):
with session.cd("./native_locator"):
session.run("cargo", "build", "--release", "--package", "python-finder", external=True)
if not pathlib.Path(pathlib.Path.cwd() / "bin").exists():
pathlib.Path(pathlib.Path.cwd() / "bin").mkdir()

if not pathlib.Path(pathlib.Path.cwd() / "bin" / ".gitignore").exists():
pathlib.Path(pathlib.Path.cwd() / "bin" / ".gitignore").write_text("*\n", encoding="utf-8")
pathlib.Path(pathlib.Path.cwd() / "bin" / ".gitignore").write_text(
"*\n", encoding="utf-8"
)

ext = sysconfig.get_config_var("EXE") or ""
target = os.environ.get("CARGO_TARGET", None)

if sys.platform == "win32":
shutil.copy(
"./target/release/python-finder.exe",
"./bin/python-finder.exe",
session.run("cargo", "fetch", external=True)
if target:
session.run(
"cargo",
"build",
"--frozen",
"--release",
"--target",
target,
"--package",
"python-finder",
external=True,
)
source = f"./target/{target}/release/python-finder{ext}"
dest = f"./bin/python-finder{ext}"
shutil.copy(source, dest)
else:
shutil.copy(
"./target/release/python-finder",
"./bin/python-finder",
session.run(
"cargo",
"build",
"--frozen",
"--release",
"--package",
"python-finder",
external=True,
)

source = f"./target/release/python-finder{ext}"
dest = f"./bin/python-finder{ext}"
shutil.copy(source, dest)


@nox.session()
def setup_repo(session: nox.Session):
Expand Down
Loading
Loading