Skip to content

Commit

Permalink
fix: Ensure that Node.js native addon targets GLIBC 2.28 on `x86_64-u…
Browse files Browse the repository at this point in the history
…nknown-linux-gnu` (#909)

Required for
NomicFoundation/hardhat-vscode#546 #639

Without this, we host-compiled our native addon with the GLIBC of the
runner (`ubuntu-22.04`), which is 2.33. That's too high and will cause
linking issues on older, stable distributions such as Debian 11 (2.31),
Debian 10 (2.28), Ubuntu 20.04 (2.31) etc.

The Linux requirement for VS Code atm is 2.28
(https://code.visualstudio.com/docs/supporting/requirements#_additional-linux-requirements)
and was bumped in [1.86](https://code.visualstudio.com/updates/v1_86).
Prior to that, the required version was 2.17 and we might consider
targeting it instead, until we bump the required VS Code engine for the
shipped extension (cc @kanej).

Here is the latest runs that check that the `infra publish npm
--dry-run` executes as expected and passes the relevant checks on our
CI:
https://github.com/Xanewok/slang/actions/runs/8472800732/job/23215682564.
The built artifacts are uploaded as part of the pipeline so they can be
additionally downloaded and inspected manually for the GLIBC symbols.
  • Loading branch information
Xanewok authored Apr 8, 2024
1 parent aa1c073 commit cdcdf8c
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 55 deletions.
59 changes: 20 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ anyhow = { version = "1.0.81", features = ["backtrace", "std"] }
ariadne = { version = "0.2.0" }
cargo-emit = { version = "0.2.1" }
cargo-xwin = { version = "0.14.2" }
cargo-zigbuild = { version = "0.18.3" }
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
clap_complete = { version = "4.5.1" }
console = { version = "0.15.8" }
Expand Down Expand Up @@ -114,6 +115,7 @@ syn = { version = "2.0.57", features = [
"parsing",
"printing",
] }
tempfile = { version = "3.10.1" }
tera = { version = "1.19.1" }
thiserror = { version = "1.0.58" }
trybuild = { version = "1.0.91" }
Expand Down
3 changes: 2 additions & 1 deletion crates/infra/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ clap_complete = { workspace = true }
infra_utils = { workspace = true }
itertools = { workspace = true }
markdown = { workspace = true }
regex = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }
toml = { workspace = true }

[lints]
workspace = true

14 changes: 9 additions & 5 deletions crates/infra/cli/src/commands/publish/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use infra_utils::github::GitHub;
use infra_utils::paths::PathExtensions;
use itertools::Itertools;

use crate::commands::publish::DryRun;

const USER_FACING_CRATE: &str = "slang_solidity";

pub fn publish_cargo() -> Result<()> {
pub fn publish_cargo(dry_run: DryRun) -> Result<()> {
let local_version = CargoWorkspace::local_version()?;
println!("Local version: {local_version}");

Expand Down Expand Up @@ -49,7 +51,7 @@ pub fn publish_cargo() -> Result<()> {

changeset.commit_changes()?;

run_cargo_publish()?;
run_cargo_publish(dry_run)?;

changeset.revert_changes()?;

Expand Down Expand Up @@ -77,14 +79,16 @@ fn update_cargo_lock() -> Result<()> {
.run()
}

fn run_cargo_publish() -> Result<()> {
fn run_cargo_publish(dry_run: DryRun) -> Result<()> {
let mut command = Command::new("cargo")
.arg("publish")
.property("--package", USER_FACING_CRATE)
.flag("--all-features");

if !GitHub::is_running_in_ci() {
println!("Attempting a dry run, since we are not running in CI.");
if dry_run.is_yes() || !GitHub::is_running_in_ci() {
println!(
"Attempting a dry run, since we are not running in CI or a dry run was requested."
);
command = command.flag("--dry-run");
}

Expand Down
8 changes: 5 additions & 3 deletions crates/infra/cli/src/commands/publish/github_release/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ use itertools::Itertools;
use markdown::{Block, Span};
use semver::Version;

pub fn publish_github_release() -> Result<()> {
use crate::commands::publish::DryRun;

pub fn publish_github_release(dry_run: DryRun) -> Result<()> {
let current_version = CargoWorkspace::local_version()?;
println!("Current version: {current_version}");

Expand All @@ -28,8 +30,8 @@ pub fn publish_github_release() -> Result<()> {
println!("{}", notes.lines().map(|l| format!(" │ {l}")).join("\n"));
println!();

if !GitHub::is_running_in_ci() {
println!("Skipping release, since we are not running in CI.");
if dry_run.is_yes() || !GitHub::is_running_in_ci() {
println!("Skipping release, since we are not running in CI or a dry run was requested.");
return Ok(());
}

Expand Down
33 changes: 30 additions & 3 deletions crates/infra/cli/src/commands/publish/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@ use crate::utils::ClapExtensions;
#[derive(Clone, Debug, Parser)]
pub struct PublishController {
command: PublishCommand,

#[arg(long)]
dry_run: bool,
}

#[derive(Clone, Copy)]
enum DryRun {
Yes,
No,
}

impl DryRun {
fn is_yes(self) -> bool {
matches!(self, DryRun::Yes)
}
}

impl From<bool> for DryRun {
fn from(value: bool) -> Self {
if value {
DryRun::Yes
} else {
DryRun::No
}
}
}

#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
Expand All @@ -34,11 +59,13 @@ impl PublishController {
pub fn execute(&self) -> Result<()> {
Terminal::step(format!("publish {name}", name = self.command.clap_name()));

let dry_run = DryRun::from(self.dry_run);

match self.command {
PublishCommand::Changesets => publish_changesets(),
PublishCommand::Npm => publish_npm(),
PublishCommand::Cargo => publish_cargo(),
PublishCommand::GithubRelease => publish_github_release(),
PublishCommand::Npm => publish_npm(dry_run),
PublishCommand::Cargo => publish_cargo(dry_run),
PublishCommand::GithubRelease => publish_github_release(dry_run),
}
}
}
11 changes: 7 additions & 4 deletions crates/infra/cli/src/commands/publish/npm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ use infra_utils::commands::Command;
use infra_utils::github::GitHub;
use infra_utils::paths::PathExtensions;

use crate::commands::publish::DryRun;
use crate::toolchains::napi::{
NapiCompiler, NapiConfig, NapiPackageKind, NapiProfile, NapiResolver,
};

pub fn publish_npm() -> Result<()> {
pub fn publish_npm(dry_run: DryRun) -> Result<()> {
let resolver = NapiResolver::solidity();

NapiCompiler::run(&resolver, NapiProfile::Release)?;
Expand All @@ -22,19 +23,21 @@ pub fn publish_npm() -> Result<()> {
&resolver,
&platform_dir,
&NapiPackageKind::Platform(platform),
dry_run,
)?;
}

// Then publish the main package, that depends on the previously published platform-specific packages:

let package_dir = resolver.main_package_dir();
publish_package(&resolver, &package_dir, &NapiPackageKind::Main)
publish_package(&resolver, &package_dir, &NapiPackageKind::Main, dry_run)
}

fn publish_package(
resolver: &NapiResolver,
package_dir: &Path,
kind: &NapiPackageKind,
dry_run: DryRun,
) -> Result<()> {
println!("Publishing: {package_dir:?}");

Expand All @@ -55,8 +58,8 @@ fn publish_package(
.args(["publish", output_dir.unwrap_str()])
.property("--access", "public");

if !GitHub::is_running_in_ci() {
println!("Doing a dry run, since we are not running in CI.");
if dry_run.is_yes() || !GitHub::is_running_in_ci() {
println!("Doing a dry run, since we are not running in CI or a dry run was requested.");
command = command.flag("--dry-run");
}

Expand Down
4 changes: 4 additions & 0 deletions crates/infra/cli/src/toolchains/napi/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use anyhow::{bail, Context, Result};
use infra_utils::commands::Command;
use infra_utils::paths::PathExtensions;

use crate::toolchains::napi::glibc;
use crate::toolchains::napi::resolver::NapiResolver;

pub enum BuildTarget {
Expand Down Expand Up @@ -61,6 +62,9 @@ impl NapiCli {

command.run()?;

#[cfg(target_env = "gnu")]
glibc::ensure_correct_glibc_for_vscode(resolver, output_dir, target)?;

let mut source_files = vec![];
let mut node_binary = None;

Expand Down
2 changes: 2 additions & 0 deletions crates/infra/cli/src/toolchains/napi/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ fn compile_all_targets(resolver: &NapiResolver) -> Result<Vec<PathBuf>> {

// Needed for cross-compiling windows targets:
CargoWorkspace::install_binary("cargo-xwin")?;
// Needed to reliably target older GBLIC on `-linux-gnu` targets when host-compiling:
CargoWorkspace::install_binary("cargo-zigbuild")?;

let mut node_binaries = vec![];

Expand Down
Loading

0 comments on commit cdcdf8c

Please sign in to comment.