Skip to content

Commit

Permalink
Veridian support (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
someone13574 authored May 25, 2024
1 parent 3df605a commit 525812d
Show file tree
Hide file tree
Showing 6 changed files with 458 additions and 125 deletions.
148 changes: 148 additions & 0 deletions .github/workflows/build-veridian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Build Veridian
permissions: write-all
on:
release:
types:
- published

jobs:
build-linux-x86_64:
runs-on: ubuntu-latest
steps:
- name: Checkout Veridian
uses: actions/checkout@v4
with:
repository: vivekmalneedi/veridian

- name: Install Rust Toolchain
uses: "dtolnay/rust-toolchain@v1"
with:
toolchain: stable
targets: x86_64-unknown-linux-gnu

- name: Run cargo build
run: cargo build --release --target=x86_64-unknown-linux-gnu

- name: Create archive
run: |
mv target/x86_64-unknown-linux-gnu/release/veridian veridian
strip veridian
tar -czvf veridian-x86_64-linux-gnu.tar.gz veridian
- name: Add asset to release
uses: softprops/action-gh-release@v1
with:
files: veridian-x86_64-linux-gnu.tar.gz

build-linux-aarch64:
runs-on: ubuntu-latest
steps:
- name: Checkout Veridian
uses: actions/checkout@v4
with:
repository: vivekmalneedi/veridian

- name: Install Rust Toolchain
uses: "dtolnay/rust-toolchain@v1"
with:
toolchain: stable
targets: aarch64-unknown-linux-gnu

- name: Install aarch64 compiler
run: sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y

- name: Run cargo build
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
run: cargo build --release --target=aarch64-unknown-linux-gnu

- name: Create archive
run: |
mv target/aarch64-unknown-linux-gnu/release/veridian veridian
tar -czvf veridian-aarch64-linux-gnu.tar.gz veridian
- name: Add asset to release
uses: softprops/action-gh-release@v1
with:
files: veridian-aarch64-linux-gnu.tar.gz

build-macos-x86_64:
runs-on: macos-latest
steps:
- name: Checkout Veridian
uses: actions/checkout@v4
with:
repository: vivekmalneedi/veridian

- name: Install Rust Toolchain
uses: "dtolnay/rust-toolchain@v1"
with:
toolchain: stable
targets: x86_64-apple-darwin

- name: Run cargo build
run: cargo build --release --target=x86_64-apple-darwin

- name: Create archive
run: |
mv target/x86_64-apple-darwin/release/veridian veridian
tar -czvf veridian-x86_64-macos.tar.gz veridian
- name: Add asset to release
uses: softprops/action-gh-release@v1
with:
files: veridian-x86_64-macos.tar.gz

build-macos-aarch64:
runs-on: macos-latest
steps:
- name: Checkout Veridian
uses: actions/checkout@v4
with:
repository: vivekmalneedi/veridian

- name: Install Rust Toolchain
uses: "dtolnay/rust-toolchain@v1"
with:
toolchain: stable
targets: aarch64-apple-darwin

- name: Run cargo build
run: cargo build --release --target=aarch64-apple-darwin

- name: Create archive
run: |
mv target/aarch64-apple-darwin/release/veridian veridian
tar -czvf veridian-aarch64-macos.tar.gz veridian
- name: Add asset to release
uses: softprops/action-gh-release@v1
with:
files: veridian-aarch64-macos.tar.gz

build-windows-x86_64:
runs-on: "windows-latest"
steps:
- name: Checkout Veridian
uses: actions/checkout@v4
with:
repository: vivekmalneedi/veridian

- name: Install Rust Toolchain
uses: "dtolnay/rust-toolchain@v1"
with:
toolchain: stable
targets: x86_64-pc-windows-msvc

- name: Run cargo build
run: cargo build --release --target=x86_64-pc-windows-msvc

- name: Create archive
run: Compress-Archive -Path target/x86_64-pc-windows-msvc/release/veridian.exe -DestinationPath veridian-x86_64-windows-mscv.zip

- name: Add asset to release
uses: softprops/action-gh-release@v1
with:
files: veridian-x86_64-windows-mscv.zip
8 changes: 6 additions & 2 deletions extension.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ schema_version = 1
authors = ["Owen Law <[email protected]>"]
repository = "https://github.com/someone13574/zed-verilog-extension"

[language_servers.verible-ls]
name = "Verible LS"
[language_servers.verible]
name = "Verible"
languages = ["Verilog", "SystemVerilog"]

[language_servers.veridian]
name = "Veridian"
languages = ["Verilog", "SystemVerilog"]

[grammars.verilog]
Expand Down
25 changes: 25 additions & 0 deletions src/language_server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub mod verible;
pub mod veridian;

use zed_extension_api::{self as zed};

pub trait LanguageServer {
const LANGUAGE_SERVER_ID: &'static str;
const DOWNLOAD_REPO: &'static str;

fn binary_name(os: zed::Os) -> String;
fn binary_path(version: &str, os: zed::Os, arch: zed::Architecture) -> zed::Result<String>;
fn asset_name(version: &str, os: zed::Os, arch: zed::Architecture) -> zed::Result<String>;

fn download_binary(
&self,
language_server_id: &zed::LanguageServerId,
os: zed::Os,
arch: zed::Architecture,
) -> zed::Result<String>;
fn get_cached_binary(
&mut self,
language_server_id: &zed::LanguageServerId,
worktree: &zed::Worktree,
) -> zed::Result<String>;
}
125 changes: 125 additions & 0 deletions src/language_server/verible.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use super::LanguageServer;
use std::fs;
use zed_extension_api::{self as zed};

#[derive(Default)]
pub struct Verible {
cached_binary: Option<String>,
}

impl LanguageServer for Verible {
const LANGUAGE_SERVER_ID: &'static str = "verible";
const DOWNLOAD_REPO: &'static str = "chipsalliance/verible";

fn binary_name(os: zed::Os) -> String {
match os {
zed::Os::Mac | zed::Os::Linux => "verible-verilog-ls",
zed::Os::Windows => "verible-verilog-ls.exe",
}
.to_string()
}

fn binary_path(version: &str, os: zed::Os, _arch: zed::Architecture) -> zed::Result<String> {
let dir = format!(
"verible-{version}{}",
match os {
zed::Os::Mac => "-macOS/bin",
zed::Os::Linux => "/bin",
zed::Os::Windows => "-win64/",
}
);
let binary_name = Self::binary_name(os);

Ok(format!("{dir}/{binary_name}"))
}

fn asset_name(version: &str, os: zed::Os, arch: zed::Architecture) -> zed::Result<String> {
let suffix = match (os, arch) {
(zed::Os::Mac, zed::Architecture::Aarch64)
| (zed::Os::Mac, zed::Architecture::X8664) => "macOS.tar.gz",
(zed::Os::Linux, zed::Architecture::Aarch64) => "linux-static-arm64.tar.gz",
(zed::Os::Linux, zed::Architecture::X8664) => "linux-static-x86_64.tar.gz",
(zed::Os::Windows, zed::Architecture::X8664) => "win64.zip",
_ => {
return Err(format!("architecture {arch:?} not supported on {os:?}"));
}
};

Ok(format!("verible-{version}-{suffix}"))
}

fn download_binary(
&self,
language_server_id: &zed::LanguageServerId,
os: zed::Os,
arch: zed::Architecture,
) -> zed::Result<String> {
zed::set_language_server_installation_status(
language_server_id,
&zed::LanguageServerInstallationStatus::CheckingForUpdate,
);

let release = zed::latest_github_release(
Self::DOWNLOAD_REPO,
zed::GithubReleaseOptions {
require_assets: true,
pre_release: false,
},
)?;

let asset_name = Self::asset_name(&release.version, os, arch)?;
let asset = release
.assets
.into_iter()
.find(|asset| asset.name == asset_name)
.ok_or(format!("no asset found matching `{asset_name}`"))?;
let binary_path = Self::binary_path(&release.version, os, arch)?;

if !fs::metadata(&binary_path).map_or(false, |metadata| metadata.is_file()) {
zed::set_language_server_installation_status(
language_server_id,
&zed::LanguageServerInstallationStatus::Downloading,
);

zed::download_file(
&asset.download_url,
"",
match os {
zed::Os::Mac | zed::Os::Linux => zed::DownloadedFileType::GzipTar,
zed::Os::Windows => zed::DownloadedFileType::Zip,
},
)
.map_err(|err| format!("failed to download file `{}`: {err}", asset.download_url))?;
}

zed::set_language_server_installation_status(
language_server_id,
&zed::LanguageServerInstallationStatus::None,
);

Ok(binary_path)
}

fn get_cached_binary(
&mut self,
language_server_id: &zed::LanguageServerId,
worktree: &zed::Worktree,
) -> zed::Result<String> {
if let Some(path) = &self.cached_binary {
if !fs::metadata(path).map_or(false, |metadata| metadata.is_file()) {
self.cached_binary = None;
} else {
return Ok(path.to_string());
}
}

let (os, arch) = zed::current_platform();
if let Some(path) = worktree.which(&Self::binary_name(os)) {
self.cached_binary = Some(path);
} else {
self.cached_binary = Some(self.download_binary(language_server_id, os, arch)?);
}

Ok(self.cached_binary.clone().unwrap())
}
}
Loading

0 comments on commit 525812d

Please sign in to comment.