Skip to content

Commit

Permalink
Merge branch 'main' into ciro/fix-Bun.write
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Dec 12, 2024
2 parents 4389d20 + 1b5cb89 commit 2158a21
Show file tree
Hide file tree
Showing 82 changed files with 5,863 additions and 1,299 deletions.
2 changes: 0 additions & 2 deletions .buildkite/scripts/upload-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,6 @@ function create_release() {
local artifacts=(
bun-darwin-aarch64.zip
bun-darwin-aarch64-profile.zip
bun-darwin-x64.zip
bun-darwin-x64-profile.zip
bun-linux-aarch64.zip
bun-linux-aarch64-profile.zip
bun-linux-x64.zip
Expand Down
4 changes: 3 additions & 1 deletion cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "build.zig")

set(BUN_USOCKETS_SOURCE ${CWD}/packages/bun-usockets)

# hand written cpp source files. Full list of "source" code (including codegen) is in BUN_CPP_SOURCES
file(GLOB BUN_CXX_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/io/*.cpp
${CWD}/src/bun.js/modules/*.cpp
Expand Down Expand Up @@ -632,6 +633,7 @@ register_command(
list(APPEND BUN_CPP_SOURCES
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
${BUN_ERROR_CODE_OUTPUTS}
${VENDOR_PATH}/picohttpparser/picohttpparser.c
${NODEJS_HEADERS_PATH}/include/node/node_version.h
${BUN_ZIG_GENERATED_CLASSES_OUTPUTS}
Expand Down Expand Up @@ -890,7 +892,7 @@ if(LINUX)
-Wl,--wrap=statx
)
endif()

if(ARCH STREQUAL "x64")
target_link_options(${bun} PUBLIC
-Wl,--wrap=fcntl
Expand Down
52 changes: 11 additions & 41 deletions packages/bun-build-mdx-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,25 @@
use bun_native_plugin::{define_bun_plugin, BunLoader, OnBeforeParse};
use bun_native_plugin::{anyhow, bun, define_bun_plugin, BunLoader, Result};
use mdxjs::{compile, Options as CompileOptions};
use napi_derive::napi;

#[macro_use]
extern crate napi;

define_bun_plugin!("bun-mdx-rs");

#[no_mangle]
pub extern "C" fn bun_mdx_rs(
args: *const bun_native_plugin::sys::OnBeforeParseArguments,
result: *mut bun_native_plugin::sys::OnBeforeParseResult,
) {
let args = unsafe { &*args };

let mut handle = match OnBeforeParse::from_raw(args, result) {
Ok(handle) => handle,
Err(_) => {
return;
}
};

let source_str = match handle.input_source_code() {
Ok(source_str) => source_str,
Err(_) => {
handle.log_error("Failed to fetch source code");
return;
}
};
#[bun]
pub fn bun_mdx_rs(handle: &mut OnBeforeParse) -> Result<()> {
let source_str = handle.input_source_code()?;

let mut options = CompileOptions::gfm();

// Leave it as JSX for Bun to handle
options.jsx = true;

let path = match handle.path() {
Ok(path) => path,
Err(e) => {
handle.log_error(&format!("Failed to get path: {:?}", e));
return;
}
};
let path = handle.path()?;
options.filepath = Some(path.to_string());

match compile(&source_str, &options) {
Ok(compiled) => {
handle.set_output_source_code(compiled, BunLoader::BUN_LOADER_JSX);
}
Err(_) => {
handle.log_error("Failed to compile MDX");
return;
}
}
let jsx = compile(&source_str, &options)
.map_err(|e| anyhow::anyhow!("Failed to compile MDX: {:?}", e))?;

handle.set_output_source_code(jsx, BunLoader::BUN_LOADER_JSX);

Ok(())
}
99 changes: 99 additions & 0 deletions packages/bun-native-plugin-rs/Cargo.lock

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

10 changes: 10 additions & 0 deletions packages/bun-native-plugin-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ edition = "2021"

[build-dependencies]
bindgen = "0.70.1"

[dependencies]
anyhow = "1.0.94"
bun-macro = { path = "./bun-macro" }
napi = { version = "2.14.1", default-features = false, features = ["napi4"] }

[features]
default = ["napi"]
napi = []

Loading

0 comments on commit 2158a21

Please sign in to comment.