diff --git a/packages/vscode-codeql-native/.github/.env b/packages/vscode-codeql-native/.github/.env new file mode 100644 index 00000000000..cbe24b0d86e --- /dev/null +++ b/packages/vscode-codeql-native/.github/.env @@ -0,0 +1,5 @@ +NODE_VERSION=20.x +NPM_REGISTRY=https://registry.npmjs.org +RUST_VERSION=stable +ACTIONS_USER=github-actions +ACTIONS_EMAIL=github-actions@github.com diff --git a/packages/vscode-codeql-native/.github/actions/setup/action.yml b/packages/vscode-codeql-native/.github/actions/setup/action.yml new file mode 100644 index 00000000000..f3255c1aac2 --- /dev/null +++ b/packages/vscode-codeql-native/.github/actions/setup/action.yml @@ -0,0 +1,76 @@ +name: 'Setup Neon' +description: 'Setup the Neon toolchain.' +inputs: + platform: + description: 'Platform being built for.' + required: false + default: '' + use-rust: + description: 'Install Rust?' + required: false + default: 'true' + use-cross: + description: 'Install cross-rs?' + required: false + default: 'false' + workspace: + description: 'Path to workspace being setup.' + required: false + default: '.' +outputs: + rust: + description: 'Rust version installed.' + value: ${{ steps.rust.outputs.version }} + node: + description: 'Node version installed.' + value: ${{ steps.node.outputs.version }} + target: + description: 'Rust target architecture installed.' + value: ${{ steps.target.outputs.target }} +runs: + using: "composite" + steps: + - name: Set Environment Variables + uses: falti/dotenv-action@d1cd55661714e830a6e26f608f81d36e23424fed # v1.1.2 + with: + path: ./.github/.env + export-variables: true + keys-case: bypass + - name: Install Node + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + registry-url: ${{ env.NPM_REGISTRY }} + cache: npm + - name: Install Dependencies + shell: bash + run: npm ci + - name: Compute Rust Target + if: ${{ inputs['use-rust'] == 'true' }} + id: target + shell: bash + run: echo target=$(npx neon list-platforms | jq -r '.["${{ inputs.platform }}"]') | tee -a $GITHUB_OUTPUT + working-directory: ${{ inputs.workspace }} + - name: Install Rust + if: ${{ inputs['use-rust'] == 'true' }} + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.RUST_VERSION }} + target: ${{ steps.target.outputs.target }} + override: true + - name: Install cross-rs + if: ${{ inputs['use-cross'] == 'true' }} + uses: baptiste0928/cargo-install@v2 + with: + crate: cross + - name: Node Version + id: node + shell: bash + run: | + echo version=$(node -e 'console.log(process.versions.node)') | tee -a $GITHUB_OUTPUT + - name: Rust Version + if: ${{ inputs['use-rust'] == 'true' }} + id: rust + shell: bash + run: | + echo version=$(cargo -Vv | fgrep release: | cut -d' ' -f2) | tee -a $GITHUB_OUTPUT diff --git a/packages/vscode-codeql-native/.github/workflows/build.yml b/packages/vscode-codeql-native/.github/workflows/build.yml new file mode 100644 index 00000000000..a74d770c934 --- /dev/null +++ b/packages/vscode-codeql-native/.github/workflows/build.yml @@ -0,0 +1,137 @@ +name: Build + +on: + workflow_call: + inputs: + ref: + description: 'The branch, tag, or SHA to check out' + required: true + type: string + update-version: + description: 'Update version before building?' + required: false + type: boolean + default: false + version: + description: 'Version update (ignored if update-version is false)' + required: false + type: string + default: 'patch' + github-release: + description: 'Publish GitHub release?' + required: false + type: boolean + default: false + tag: + description: 'The release tag (ignored if github-release is false)' + required: false + type: string + default: '' + +jobs: + matrix: + name: Matrix + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.matrix.outputs.result }} + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Look Up Matrix Data + id: matrixData + shell: bash + run: echo "json=$(npx neon show ci github | jq -rc)" | tee -a $GITHUB_OUTPUT + - name: Compute Matrix + id: matrix + uses: actions/github-script@v7 + with: + script: | + const platforms = ${{ steps.matrixData.outputs.json }}; + const macOS = platforms.macOS.map(platform => { + return { os: "macos-latest", platform, script: "build" }; + }); + const windows = platforms.Windows.map(platform => { + return { os: "windows-latest", platform, script: "build" }; + }); + const linux = platforms.Linux.map(platform => { + return { os: "ubuntu-latest", platform, script: "cross" }; + }); + return [...macOS, ...windows, ...linux]; + + binaries: + name: Binaries + needs: [matrix] + strategy: + matrix: + cfg: ${{ fromJSON(needs.matrix.outputs.matrix) }} + runs-on: ${{ matrix.cfg.os }} + permissions: + contents: write + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + - name: Setup Neon Environment + id: neon + uses: ./.github/actions/setup + with: + use-cross: ${{ matrix.cfg.script == 'cross' }} + platform: ${{ matrix.cfg.platform }} + - name: Update Version + if: ${{ inputs.update-version }} + shell: bash + run: | + git config --global user.name $ACTIONS_USER + git config --global user.email $ACTIONS_EMAIL + npm version ${{ inputs.version }} -m "v%s" + - name: Build + shell: bash + env: + CARGO_BUILD_TARGET: ${{ steps.neon.outputs.target }} + NEON_BUILD_PLATFORM: ${{ matrix.cfg.platform }} + run: npm run ${{ matrix.cfg.script }} + - name: Pack + id: pack + shell: bash + run: | + mkdir -p dist + echo filename=$(basename $(npm pack ./platforms/${{ matrix.cfg.platform }} --silent --pack-destination=./dist --json | jq -r '.[0].filename')) | tee -a $GITHUB_OUTPUT + - name: Release + if: ${{ inputs.github-release }} + uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 + with: + files: ./dist/${{ steps.pack.outputs.filename }} + tag_name: ${{ inputs.tag }} + + main: + name: Main + needs: [matrix] + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + ref: ${{ inputs.ref }} + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Pack + id: pack + shell: bash + run: | + mkdir -p dist + echo "filename=$(npm pack --silent --pack-destination=./dist)" | tee -a $GITHUB_OUTPUT + - name: Release + if: ${{ inputs.github-release }} + uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 # v2.0.4 + with: + files: ./dist/${{ steps.pack.outputs.filename }} + tag_name: ${{ inputs.tag }} diff --git a/packages/vscode-codeql-native/.github/workflows/release.yml b/packages/vscode-codeql-native/.github/workflows/release.yml new file mode 100644 index 00000000000..1a86f9e7b75 --- /dev/null +++ b/packages/vscode-codeql-native/.github/workflows/release.yml @@ -0,0 +1,135 @@ +name: Release + +run-name: | + ${{ (inputs.dryrun && 'Dry run') + || format('Release: {0}', (inputs.version == 'custom' && inputs.custom) || inputs.version) }} + +on: + workflow_dispatch: + inputs: + dryrun: + description: 'Dry run (no npm publish)' + required: false + type: boolean + default: true + version: + description: 'Version component to update (or "custom" to provide exact version)' + required: true + type: choice + options: + - patch + - minor + - major + - prepatch + - preminor + - premajor + - prerelease + - custom + custom: + description: 'Custom version' + required: false + default: '' + +jobs: + setup: + name: Setup + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + dryrun: ${{ steps.dryrun.outputs.dryrun }} + publish: ${{ steps.publish.outputs.publish }} + ref: ${{ steps.tag.outputs.tag || github.event.repository.default_branch }} + tag: ${{ steps.tag.outputs.tag || '' }} + steps: + - name: Validate Workflow Inputs + if: ${{ inputs.version == 'custom' && inputs.custom == '' }} + shell: bash + run: | + echo '::error::No custom version number provided' + exit 1 + - id: dryrun + name: Validate Dry Run Event + if: ${{ inputs.dryrun }} + shell: bash + run: echo dryrun=true | tee -a $GITHUB_OUTPUT + - id: publish + name: Validate Publish Event + if: ${{ !inputs.dryrun }} + shell: bash + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + if [[ -z $NPM_TOKEN ]]; then + echo "::error::Secret NPM_TOKEN is not defined for this GitHub repo." + echo "::error::To publish to npm, this action requires:" + echo "::error:: • an npm access token;" + echo "::error:: • with Read-Write access to this project's npm packages;" + echo "::error:: • stored as a repo secret named NPM_TOKEN." + echo "::error::See https://docs.npmjs.com/about-access-tokens for info about creating npm tokens." + echo "::error:: 💡 The simplest method is to create a Classic npm token of type Automation." + echo "::error:: 💡 For greater security, consider using a Granual access token." + echo "::error::See https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions for info about how to store GitHub repo secrets." + exit 1 + fi + echo publish=true | tee -a $GITHUB_OUTPUT + - name: Checkout Code + uses: actions/checkout@v3 + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Tag Release + if: ${{ !inputs.dryrun }} + id: tag + shell: bash + run: | + git config --global user.name $ACTIONS_USER + git config --global user.email $ACTIONS_EMAIL + npm version -m 'v%s' '${{ (inputs.version == 'custom' && inputs.custom) || inputs.version }}' + git push --follow-tags + echo tag=$(git describe --abbrev=0) | tee -a $GITHUB_OUTPUT + + build: + name: Build + needs: [setup] + permissions: + contents: write + uses: ./.github/workflows/build.yml + with: + ref: ${{ needs.setup.outputs.ref }} + tag: ${{ needs.setup.outputs.tag }} + update-version: ${{ !!needs.setup.outputs.dryrun }} + version: ${{ (inputs.version == 'custom' && inputs.custom) || inputs.version }} + github-release: ${{ !!needs.setup.outputs.publish }} + + publish: + name: Publish + if: ${{ needs.setup.outputs.publish }} + needs: [setup, build] + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + ref: ${{ needs.setup.outputs.ref }} + - name: Setup Neon Environment + uses: ./.github/actions/setup + with: + use-rust: false + - name: Fetch + uses: robinraju/release-downloader@c39a3b234af58f0cf85888573d361fb6fa281534 # v1.10 + with: + tag: ${{ needs.setup.outputs.tag }} + fileName: "*.tgz" + out-file-path: ./dist + - name: Publish + shell: bash + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + for p in ./dist/*.tgz ; do + npm publish --access public $p + done diff --git a/packages/vscode-codeql-native/.github/workflows/test.yml b/packages/vscode-codeql-native/.github/workflows/test.yml new file mode 100644 index 00000000000..8814e4a423e --- /dev/null +++ b/packages/vscode-codeql-native/.github/workflows/test.yml @@ -0,0 +1,71 @@ +name: Test + +run-name: | + ${{ (github.event_name == 'pull_request' && format('Test (PR #{0}): {1}', github.event.number, github.event.pull_request.title)) + || format('Test: {0}', github.event.head_commit.message) }} + +on: + # Event: A maintainer has pushed commits or merged a PR to main. + push: + # Limiting push events to 'main' prevents duplicate runs of this workflow + # when maintainers push to internal PRs. + branches: + - main + + # Event: A contributor has created or updated a PR. + pull_request: + types: [opened, synchronize, reopened, labeled] + branches: + - main + +jobs: + pr: + name: Pull Request Details + runs-on: ubuntu-latest + if: ${{ github.event_name == 'pull_request' }} + outputs: + branch: ${{ steps.pr-ref.outputs.branch || github.event.repository.default_branch }} + steps: + - name: PR Branch + id: pr-ref + shell: bash + run: echo "branch=$(gh pr view $PR_NO --repo $REPO --json headRefName --jq '.headRefName')" | tee -a "$GITHUB_OUTPUT" + env: + REPO: ${{ github.repository }} + PR_NO: ${{ github.event.number }} + GH_TOKEN: ${{ github.token }} + + # Labeling a PR with a `ci:full-matrix` label does a full matrix build on + # every run of this workflow for that PR, in addition to the other tests. + full-matrix: + name: Build + if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'ci:full-matrix') }} + needs: [pr] + permissions: + contents: write + uses: ./.github/workflows/build.yml + with: + ref: ${{ needs.pr.outputs.branch }} + update-version: true + github-release: false + + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - name: Setup Neon Environment + id: neon + uses: ./.github/actions/setup + with: + platform: linux-x64-gnu + - name: Build + shell: bash + env: + CARGO_BUILD_TARGET: ${{ steps.neon.outputs.target }} + NEON_BUILD_PLATFORM: linux-x64-gnu + run: npm run debug + - name: Test + shell: bash + run: npm test diff --git a/packages/vscode-codeql-native/.gitignore b/packages/vscode-codeql-native/.gitignore new file mode 100644 index 00000000000..8ec40c75533 --- /dev/null +++ b/packages/vscode-codeql-native/.gitignore @@ -0,0 +1,8 @@ +target +index.node +**/node_modules +**/.DS_Store +npm-debug.log* +lib +cargo.log +cross.log diff --git a/packages/vscode-codeql-native/Cargo.lock b/packages/vscode-codeql-native/Cargo.lock new file mode 100644 index 00000000000..c993941d969 --- /dev/null +++ b/packages/vscode-codeql-native/Cargo.lock @@ -0,0 +1,233 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "cfg-if" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" + +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "libloading" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linkme" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1b1703c00b2a6a70738920544aa51652532cacddfec2e162d2e29eae01e665c" +dependencies = [ + "linkme-impl", +] + +[[package]] +name = "linkme-impl" +version = "0.3.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04d55ca5d5a14363da83bf3c33874b8feaa34653e760d5216d7ef9829c88001a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "neon" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74c1d298c79e60a3f5a1e638ace1f9c1229d2a97bd3a9e40a63b67c8efa0f1e1" +dependencies = [ + "either", + "getrandom", + "libloading", + "linkme", + "neon-macros", + "once_cell", + "semver", + "send_wrapper", + "smallvec", +] + +[[package]] +name = "neon-macros" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39e43767817fc963f90f400600967a2b2403602c6440685d09a6bc4e02b70b1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" + +[[package]] +name = "send_wrapper" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "vscode-codeql-native" +version = "0.1.0" +dependencies = [ + "neon", + "winsafe", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "windows-targets" +version = "0.53.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c66f69fcc9ce11da9966ddb31a40968cad001c5bedeb5c2b82ede4253ab48aef" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + +[[package]] +name = "winsafe" +version = "0.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271ae8f63c109d73bc6fcf352b117166757fabcce6a769649ef18303dbf2491" diff --git a/packages/vscode-codeql-native/Cargo.toml b/packages/vscode-codeql-native/Cargo.toml new file mode 100644 index 00000000000..39bb84e0aa4 --- /dev/null +++ b/packages/vscode-codeql-native/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "vscode-codeql-native" +version = "0.1.0" +license = "MIT" +edition = "2024" +exclude = ["index.node"] + +[lib] +crate-type = ["cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +neon = "1.1" + +[target.'cfg(windows)'.dependencies] +winsafe = { version = "0.0.24", features = ["kernel"] } + +[profile.release] +strip = "debuginfo" +lto = true diff --git a/packages/vscode-codeql-native/README.md b/packages/vscode-codeql-native/README.md new file mode 100644 index 00000000000..40d75e74efb --- /dev/null +++ b/packages/vscode-codeql-native/README.md @@ -0,0 +1,104 @@ +# vscode-codeql-native + +This project was bootstrapped by [create-neon](https://www.npmjs.com/package/create-neon). + +## Building vscode-codeql-native + +Building vscode-codeql-native requires a [supported version of Node and Rust](https://github.com/neon-bindings/neon#platform-support). + +To run the build, run: + +```sh +$ npm run build +``` + +This command uses the [@neon-rs/cli](https://www.npmjs.com/package/@neon-rs/cli) utility to assemble the binary Node addon from the output of `cargo`. + +## Exploring vscode-codeql-native + +After building vscode-codeql-native, you can explore its exports at the Node console: + +```sh +$ npm i +$ npm run build +$ node +> require('.').greeting('node') +{ message: 'hello node' } +``` + +## Available Scripts + +In the project directory, you can run: + +#### `npm run build` + +Builds the Node addon (`index.node`) from source, generating a release build with `cargo --release`. + +Additional [`cargo build`](https://doc.rust-lang.org/cargo/commands/cargo-build.html) arguments may be passed to `npm run build` and similar commands. For example, to enable a [cargo feature](https://doc.rust-lang.org/cargo/reference/features.html): + +``` +npm run build -- --feature=beetle +``` + +#### `npm run debug` + +Similar to `npm run build` but generates a debug build with `cargo`. + +#### `npm run cross` + +Similar to `npm run build` but uses [cross-rs](https://github.com/cross-rs/cross) to cross-compile for another platform. Use the [`CARGO_BUILD_TARGET`](https://doc.rust-lang.org/cargo/reference/config.html#buildtarget) environment variable to select the build target. + +#### `npm run release` + +Initiate a full build and publication of a new patch release of this library via GitHub Actions. + +#### `npm run dryrun` + +Initiate a dry run of a patch release of this library via GitHub Actions. This performs a full build but does not publish the final result. + +#### `npm test` + +Runs the unit tests by calling `cargo test`. You can learn more about [adding tests to your Rust code](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) from the [Rust book](https://doc.rust-lang.org/book/). + +## Project Layout + +The directory structure of this project is: + +``` +vscode-codeql-native/ +├── Cargo.toml +├── README.md +├── lib/ +├── src/ +| ├── index.mts +| └── index.cts +├── crates/ +| └── vscode-codeql-native/ +| └── src/ +| └── lib.rs +├── platforms/ +├── package.json +└── target/ +``` + +| Entry | Purpose | +|----------------|------------------------------------------------------------------------------------------------------------------------------------------| +| `Cargo.toml` | The Cargo [manifest file](https://doc.rust-lang.org/cargo/reference/manifest.html), which informs the `cargo` command. | +| `README.md` | This file. | +| `lib/` | The directory containing the generated output from [tsc](https://typescriptlang.org). | +| `src/` | The directory containing the TypeScript source files. | +| `index.mts` | Entry point for when this library is loaded via [ESM `import`](https://nodejs.org/api/esm.html#modules-ecmascript-modules) syntax. | +| `index.cts` | Entry point for when this library is loaded via [CJS `require`](https://nodejs.org/api/modules.html#requireid). | +| `crates/` | The directory tree containing the Rust source code for the project. | +| `lib.rs` | Entry point for the Rust source code. | +| `platforms/` | The directory containing distributions of the binary addon backend for each platform supported by this library. | +| `package.json` | The npm [manifest file](https://docs.npmjs.com/cli/v7/configuring-npm/package-json), which informs the `npm` command. | +| `target/` | Binary artifacts generated by the Rust build. | + +## Learn More + +Learn more about: + +- [Neon](https://neon-bindings.com). +- [Rust](https://www.rust-lang.org). +- [Node](https://nodejs.org). diff --git a/packages/vscode-codeql-native/index.ts b/packages/vscode-codeql-native/index.ts new file mode 100644 index 00000000000..7d0121ff391 --- /dev/null +++ b/packages/vscode-codeql-native/index.ts @@ -0,0 +1,33 @@ +type NativeAddon = { + getLongPathName(shortPath: string): string; +}; + +let addonInstance: NativeAddon; + +function currentPlatform(): string | undefined { + switch (process.platform) { + case "win32": + switch (process.arch) { + case "x64": + return "win32-x64-msvc"; + } + } + + return undefined; +} + +async function addon(): Promise<{ + getLongPathName(shortPath: string): string; +}> { + if (addonInstance) { + return addonInstance; + } + + const addon = await import(`./platforms/${currentPlatform()}/index.node`); + addonInstance = addon as NativeAddon; + return addonInstance; +} + +export async function getLongPathName(shortPath: string): Promise { + return (await addon()).getLongPathName(shortPath); +} diff --git a/packages/vscode-codeql-native/package-lock.json b/packages/vscode-codeql-native/package-lock.json new file mode 100644 index 00000000000..74aeb871904 --- /dev/null +++ b/packages/vscode-codeql-native/package-lock.json @@ -0,0 +1,219 @@ +{ + "name": "vscode-codeql-native", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "vscode-codeql-native", + "version": "0.1.0", + "license": "MIT", + "devDependencies": { + "@neon-rs/cli": "^0.1.82", + "@tsconfig/node20": "^20.1.4", + "@types/node": "^20.11.16", + "typescript": "^5.3.3" + } + }, + "node_modules/@cargo-messages/android-arm-eabi": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/android-arm-eabi/-/android-arm-eabi-0.1.81.tgz", + "integrity": "sha512-cpRbgb56e9LmAj96Tixtz9/bTlaJAeplWNNv4obu+eqQyZd3ZjX04TJd9fM1bjHDGVyR9GTVlgBsbQEntIGkwg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@cargo-messages/darwin-arm64": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/darwin-arm64/-/darwin-arm64-0.1.81.tgz", + "integrity": "sha512-OwGqsw+tbJx37a/vH4T8R9qkrrFYoTIOnckbA9+MhQodE2FSWyk3HvLh+z8jjl+QZa1RSOU9Ax6gt/46h0BiTg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@cargo-messages/darwin-x64": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/darwin-x64/-/darwin-x64-0.1.81.tgz", + "integrity": "sha512-Iu761bPk25Ce6yUdDCjjeVuT8/xbBmczyaNB7oYBmAZEE5rshvCJ42TqSShYYP+S7pKkN42nBhkFooaZrqaz9g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@cargo-messages/linux-arm-gnueabihf": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/linux-arm-gnueabihf/-/linux-arm-gnueabihf-0.1.81.tgz", + "integrity": "sha512-iIuy7KTJAEhbiqlIlcxQOdW6opI6M9LXlgd/jdsHbP2FjmTyhTLnd3JCJ6JeAeidwknCDs+CFlaVmPxTKSytsg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@cargo-messages/linux-arm64-gnu": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/linux-arm64-gnu/-/linux-arm64-gnu-0.1.81.tgz", + "integrity": "sha512-QPQRsHj9m/9ga8wRBlLh8t2AXyr40+/H55FIKVj7zIjV++waY/TbSTPofDZQhMycd5VSGLKztfhahiCO7c/RAQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@cargo-messages/linux-arm64-musl": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/linux-arm64-musl/-/linux-arm64-musl-0.1.81.tgz", + "integrity": "sha512-9O0ATesIOjDTz2L01OtlGHYwP86I31/mzXMC+ryQkzbbIKj7KUiSqmEc29I14I517UYO8/sMeow6q6MVBpehlA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@cargo-messages/linux-x64-gnu": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/linux-x64-gnu/-/linux-x64-gnu-0.1.81.tgz", + "integrity": "sha512-wEFYxCdtHNiEvp5KEg17CfRCUdfRTtkL+1GASROyvYEUV6DQf6TXxfHuuWg2xlVxh5fqiTGFSRfiqFrCDL/xrw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@cargo-messages/linux-x64-musl": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/linux-x64-musl/-/linux-x64-musl-0.1.81.tgz", + "integrity": "sha512-zi5pKIh60oPwOCDQapAZ3Mya4y56MI2BoGvY8JtztYaXTorGmAoyf6jjb50Wt+HfoYYjM3OlPt03XMlCFZJnIQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@cargo-messages/win32-arm64-msvc": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/win32-arm64-msvc/-/win32-arm64-msvc-0.1.81.tgz", + "integrity": "sha512-oyiT8AYLoguF7cFOMYDsPv3eirzBcFafOOfRsFyd3+wmaPTl/DdbCq446oThRmSAsEGJpzhzj7TafcnXMBkHbg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@cargo-messages/win32-x64-msvc": { + "version": "0.1.81", + "resolved": "https://registry.npmjs.org/@cargo-messages/win32-x64-msvc/-/win32-x64-msvc-0.1.81.tgz", + "integrity": "sha512-B5Ukf4AohtIv27uCP/AgM+7vYwQ4RacI6m8ZBr2XKeSrjZXcXguzlZd+wD7bD5+wa0capvXKUskZDnpG/DcYiA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@neon-rs/cli": { + "version": "0.1.82", + "resolved": "https://registry.npmjs.org/@neon-rs/cli/-/cli-0.1.82.tgz", + "integrity": "sha512-QrlGPQp9KOGuMvjjua79lEV2QTcE16m8JatG5ITdQpBAwRQpDw5xab57W9130y2iUEfMzYtp7v6pcN1fUB0Exg==", + "dev": true, + "license": "MIT", + "bin": { + "neon": "index.js" + }, + "optionalDependencies": { + "@cargo-messages/android-arm-eabi": "0.1.81", + "@cargo-messages/darwin-arm64": "0.1.81", + "@cargo-messages/darwin-x64": "0.1.81", + "@cargo-messages/linux-arm-gnueabihf": "0.1.81", + "@cargo-messages/linux-arm64-gnu": "0.1.81", + "@cargo-messages/linux-arm64-musl": "0.1.81", + "@cargo-messages/linux-x64-gnu": "0.1.81", + "@cargo-messages/linux-x64-musl": "0.1.81", + "@cargo-messages/win32-arm64-msvc": "0.1.81", + "@cargo-messages/win32-x64-msvc": "0.1.81" + } + }, + "node_modules/@tsconfig/node20": { + "version": "20.1.6", + "resolved": "https://registry.npmjs.org/@tsconfig/node20/-/node20-20.1.6.tgz", + "integrity": "sha512-sz+Hqx9zwZDpZIV871WSbUzSqNIsXzghZydypnfgzPKLltVJfkINfUeTct31n/tTSa9ZE1ZOfKdRre1uHHquYQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/node": { + "version": "20.19.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.19.2.tgz", + "integrity": "sha512-9pLGGwdzOUBDYi0GNjM97FIA+f92fqSke6joWeBjWXllfNxZBs7qeMF7tvtOIsbY45xkWkxrdwUfUf3MnQa9gA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + } + } +} diff --git a/packages/vscode-codeql-native/package.json b/packages/vscode-codeql-native/package.json new file mode 100644 index 00000000000..726d7012d37 --- /dev/null +++ b/packages/vscode-codeql-native/package.json @@ -0,0 +1,33 @@ +{ + "name": "@github/vscode-codeql-native", + "version": "0.1.0", + "description": "", + "main": "./lib/index.js", + "scripts": { + "test": "tsc && cargo test", + "cargo-build": "tsc && cargo build --message-format=json-render-diagnostics > cargo.log", + "postcargo-build": "neon dist < cargo.log", + "debug": "npm run cargo-build --", + "build": "npm run cargo-build -- --release" + }, + "author": "GitHub", + "license": "MIT", + "types": "./lib/index.d.ts", + "files": [ + "lib", + "platforms" + ], + "neon": { + "org": "github", + "type": "library", + "platforms": [ + "windows" + ] + }, + "devDependencies": { + "@neon-rs/cli": "^0.1.82", + "@tsconfig/node20": "^20.1.4", + "@types/node": "^20.11.16", + "typescript": "^5.3.3" + } +} diff --git a/packages/vscode-codeql-native/src/lib.rs b/packages/vscode-codeql-native/src/lib.rs new file mode 100644 index 00000000000..9aaf7088b00 --- /dev/null +++ b/packages/vscode-codeql-native/src/lib.rs @@ -0,0 +1,17 @@ +use neon::types::extract::Error; + +// Use #[neon::export] to export Rust functions as JavaScript functions. +// See more at: https://docs.rs/neon/latest/neon/attr.export.html + +#[neon::export] +#[cfg(target_os = "windows")] +fn get_long_path_name(long_path: String) -> Result { + let long_path = winsafe::GetLongPathName(&long_path)?; + Ok(long_path) +} + +#[neon::export] +#[cfg(not(target_os = "windows"))] +fn get_long_path_name(_long_path: String) -> Result { + Err(Error::new("get_long_path_name is only supported on Windows")) +} diff --git a/packages/vscode-codeql-native/tsconfig.json b/packages/vscode-codeql-native/tsconfig.json new file mode 100644 index 00000000000..2bb48f66872 --- /dev/null +++ b/packages/vscode-codeql-native/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "@tsconfig/node20/tsconfig.json", + "compilerOptions": { + "module": "node16", + "declaration": true, + "outDir": "lib", + }, + "exclude": ["lib"] +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy