Skip to content

Commit

Permalink
build(ci): control per-platform features
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 6, 2022
1 parent 37eb487 commit 0d83a37
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 34 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build_test_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ jobs:
rustup default "${RUST_TOOLCHAIN}" &&
rustup target add x86_64-unknown-linux-musl &&
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && if [ ! -f $(dirname $(which yarn))/pnpm ]; then ln -s $(which yarn) $(dirname $(which yarn))/pnpm;fi &&
turbo run build-native --cache-dir=".turbo" -- --release --target x86_64-unknown-linux-musl &&
turbo run build-native --cache-dir=".turbo" -- --release --target x86_64-unknown-linux-musl --cargo-flags=--no-default-features --features sentry_rustls &&
strip packages/next-swc/native/next-swc.*.node
- host: macos-latest
target: 'aarch64-apple-darwin'
Expand Down Expand Up @@ -1293,7 +1293,7 @@ jobs:
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
build: |
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && if [ ! -f $(dirname $(which yarn))/pnpm ]; then ln -s $(which yarn) $(dirname $(which yarn))/pnpm;fi
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target armv7-unknown-linux-gnueabihf
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target armv7-unknown-linux-gnueabihf --cargo-flags=--no-default-features --features sentry_rustls
arm-linux-gnueabihf-strip packages/next-swc/native/next-swc.*.node
- host: ubuntu-latest
target: aarch64-linux-android
Expand All @@ -1303,7 +1303,7 @@ jobs:
export CXX="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"
export PATH="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" && if [ ! -f $(dirname $(which yarn))/pnpm ]; then ln -s $(which yarn) $(dirname $(which yarn))/pnpm;fi
turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-linux-android
turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-linux-android --cargo-flags=--no-default-features --features sentry_rustls
/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-strip packages/next-swc/native/next-swc.*.node
- host: ubuntu-latest
target: armv7-linux-androideabi
Expand All @@ -1313,7 +1313,7 @@ jobs:
export CXX="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"
export PATH="/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" "pnpm@${PNPM_VERSION}"
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target armv7-linux-androideabi
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target armv7-linux-androideabi --cargo-flags=--no-default-features --features sentry_rustls
/usr/local/lib/android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip packages/next-swc/native/next-swc.*.node
- host: ubuntu-latest
target: 'aarch64-unknown-linux-musl'
Expand All @@ -1324,13 +1324,13 @@ jobs:
rustup toolchain install "${RUST_TOOLCHAIN}" &&
rustup default "${RUST_TOOLCHAIN}" &&
rustup target add aarch64-unknown-linux-musl &&
turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-unknown-linux-musl &&
turbo run build-native --cache-dir=".turbo" -- --release --target aarch64-unknown-linux-musl --cargo-flags=--no-default-features --features sentry_rustls &&
llvm-strip -x packages/next-swc/native/next-swc.*.node
- host: windows-latest
target: 'aarch64-pc-windows-msvc'
build: |
npm i -g "@napi-rs/cli@${NAPI_CLI_VERSION}" "turbo@${TURBO_VERSION}" "pnpm@${PNPM_VERSION}"
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target aarch64-pc-windows-msvc
turbo run build-native-no-plugin --cache-dir=".turbo" -- --release --target aarch64-pc-windows-msvc --cargo-flags=--no-default-features
if: ${{ needs.build.outputs.isRelease == 'true' }}
needs: build
name: stable - ${{ matrix.settings.target }} - node@16
Expand Down
4 changes: 4 additions & 0 deletions packages/next-swc/crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ tracing-subscriber = "0.3.9"
tracing-chrome = "0.5.0"
wasmer = { version = "2.3.0", optional = true, default-features = false }
wasmer-wasi = { version = "2.3.0", optional = true, default-features = false }
# There are few build targets we can't use native-tls which default features rely on,
# allow to specify alternative (rustls) instead via features.
# Note to opt in rustls default-features should be disabled
# (--no-default-features --features sentry_rustls)
_sentry_native_tls = { package = "sentry", version = "0.27.0", optional = true }
_sentry_rustls = { package = "sentry", version = "0.27.0", default-features = false, features = [
"backtrace",
Expand Down
75 changes: 47 additions & 28 deletions packages/next-swc/crates/napi/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

#[cfg(feature = "sentry_native_tls")]
use _sentry_native_tls::{init, types::Dsn, ClientInitGuard, ClientOptions};
#[cfg(feature = "sentry_rustls")]
use _sentry_rustls::{init, types::Dsn, ClientInitGuard, ClientOptions};
use anyhow::{anyhow, Context, Error};
use napi::{CallContext, Env, JsBuffer, JsExternal, JsString, JsUndefined, JsUnknown, Status};
use serde::de::DeserializeOwned;
use std::{
any::type_name, borrow::Cow, cell::RefCell, convert::TryFrom, env, path::PathBuf, str::FromStr,
};
use std::{any::type_name, cell::RefCell, convert::TryFrom, env, path::PathBuf};
use tracing_chrome::{ChromeLayerBuilder, FlushGuard};
use tracing_subscriber::{filter, prelude::*, util::SubscriberInitExt, Layer};

Expand Down Expand Up @@ -160,24 +154,40 @@ pub fn init_crash_reporter(cx: CallContext) -> napi::Result<JsExternal> {
// However, this is techinically not identical to the behavior of the telemetry
// itself as sentry's debug option does not provides full payuload output.
let debug = env::var("NEXT_TELEMETRY_DEBUG").map_or_else(|_| false, |v| v == "1");
let dsn = if debug {
None
} else {
Dsn::from_str("https://7619e5990e3045cda747e50e6ed087a7@o205439.ingest.sentry.io/6528434")

#[cfg(not(all(target_os = "windows", target_arch = "aarch64")))]
let guard = {
#[cfg(feature = "sentry_native_tls")]
use _sentry_native_tls::{init, types::Dsn, ClientOptions};
#[cfg(feature = "sentry_rustls")]
use _sentry_rustls::{init, types::Dsn, ClientOptions};
use std::{borrow::Cow, str::FromStr};

let dsn = if debug {
None
} else {
Dsn::from_str(
"https://7619e5990e3045cda747e50e6ed087a7@o205439.ingest.sentry.io/6528434",
)
.ok()
};

Some(init(ClientOptions {
release: Some(Cow::Borrowed(PACKAGE_VERSION)),
dsn,
debug,
// server_name includes device host name, which _can_ be considered as PII depends on
// the machine name.
server_name: Some(Cow::Borrowed("[REDACTED]")),
..Default::default()
}))
};

let guard = init(ClientOptions {
release: Some(Cow::Borrowed(PACKAGE_VERSION)),
dsn,
debug,
// server_name includes device host name, which _can_ be considered as PII depends on
// the machine name.
server_name: Some(Cow::Borrowed("[REDACTED]")),
..Default::default()
});
// aarch64_msvc neither compiles native-tls nor rustls for sentry transport
#[cfg(all(target_os = "windows", target_arch = "aarch64"))]
let guard: Option<usize> = None;

let guard_cell = RefCell::new(Some(guard));
let guard_cell = RefCell::new(guard);
cx.env.create_external(guard_cell, None)
}

Expand All @@ -186,13 +196,22 @@ pub fn init_crash_reporter(cx: CallContext) -> napi::Result<JsExternal> {
/// in napi context.
#[js_function(1)]
pub fn teardown_crash_reporter(cx: CallContext) -> napi::Result<JsUndefined> {
let guard_external = cx.get::<JsExternal>(0)?;
let guard_cell = &*cx
.env
.get_value_external::<RefCell<Option<ClientInitGuard>>>(&guard_external)?;

if let Some(guard) = guard_cell.take() {
drop(guard);
#[cfg(not(all(target_os = "windows", target_arch = "aarch64")))]
{
#[cfg(feature = "sentry_native_tls")]
use _sentry_native_tls::ClientInitGuard;
#[cfg(feature = "sentry_rustls")]
use _sentry_rustls::ClientInitGuard;

let guard_external = cx.get::<JsExternal>(0)?;
let guard_cell = &*cx
.env
.get_value_external::<RefCell<Option<ClientInitGuard>>>(&guard_external)?;

if let Some(guard) = guard_cell.take() {
drop(guard);
}
}

cx.env.get_undefined()
}

0 comments on commit 0d83a37

Please sign in to comment.