mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
refactor: cleanup unused files
This commit is contained in:
parent
5624c9a124
commit
5f1caa0e61
15
build.zig
15
build.zig
@ -1,18 +1,13 @@
|
||||
const build_zon = @import("build.zig.zon");
|
||||
const std = @import("std");
|
||||
const initlib = @import("src/build/init.zig");
|
||||
|
||||
const buildlib = @import("src/build/main.zig");
|
||||
const build_zon = @import("build.zig.zon");
|
||||
|
||||
// --- Public API (setting up ZX Site) --- //
|
||||
/// Options for initializing
|
||||
pub const InitOptions = buildlib.initlib.InitOptions;
|
||||
/// Initialize a ZX project (sets up ZX, dependencies, executables, wasm executable and `serve` step)
|
||||
pub const init = buildlib.initlib.init;
|
||||
pub const InitOptions = initlib.InitOptions;
|
||||
|
||||
/// Default plugins
|
||||
/// #### Available plugins
|
||||
/// - tailwind: Tailwind CSS plugin
|
||||
pub const plugins = buildlib.plugins;
|
||||
/// Initialize a Ziex project (sets up Ziex, dependencies, executables, wasm executable and `serve` step)
|
||||
pub const init = initlib.init;
|
||||
|
||||
pub fn build(b: *std.Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
|
||||
2
pkg/transformjs/.gitignore
vendored
2
pkg/transformjs/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
# Rust
|
||||
target
|
||||
1017
pkg/transformjs/Cargo.lock
generated
1017
pkg/transformjs/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,17 +0,0 @@
|
||||
[package]
|
||||
name = "transformjs"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
name = "transformjs"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
oxc = "0.98.0"
|
||||
oxc_allocator = "0.98.0"
|
||||
oxc_codegen = "0.98.0"
|
||||
oxc_parser = "0.98.0"
|
||||
oxc_semantic = "0.98.0"
|
||||
oxc_span = "0.98.0"
|
||||
oxc_transformer = "0.98.0"
|
||||
@ -1,18 +0,0 @@
|
||||
language = "C"
|
||||
header = "/* TransformJS C Bindings - Generated by cbindgen */"
|
||||
include_guard = "TRANSFORMJS_H"
|
||||
include_version = true
|
||||
autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
|
||||
namespace = "transformjs"
|
||||
no_includes = false
|
||||
sys_includes = ["stddef.h", "stdint.h"]
|
||||
usize_is_size_t = true
|
||||
|
||||
[export]
|
||||
exclude = []
|
||||
include = ["TransformResult", "transformjs_transform", "transformjs_free_string", "transformjs_free_result"]
|
||||
|
||||
[parse]
|
||||
parse_deps = false
|
||||
include = ["transformjs"]
|
||||
exclude = []
|
||||
@ -1,290 +0,0 @@
|
||||
//! # TransformJS C FFI Library
|
||||
//!
|
||||
//! This library exposes JavaScript/TypeScript transformation functionality
|
||||
//! through a C-compatible interface for use in Zig and other languages.
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::os::raw::{c_char, c_int};
|
||||
use std::path::Path;
|
||||
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_codegen::Codegen;
|
||||
use oxc_parser::Parser;
|
||||
use oxc_semantic::SemanticBuilder;
|
||||
use oxc_span::SourceType;
|
||||
use oxc_transformer::{HelperLoaderMode, TransformOptions as RustTransformOptions, Transformer, Module};
|
||||
|
||||
/// Helper loader mode
|
||||
#[repr(C)]
|
||||
pub enum TransformHelperLoaderMode {
|
||||
/// Runtime mode - helpers are inlined
|
||||
Runtime = 0,
|
||||
/// External mode - helpers are imported
|
||||
External = 1,
|
||||
}
|
||||
|
||||
/// Transform options structure (C-compatible)
|
||||
#[repr(C)]
|
||||
pub struct CTransformOptions {
|
||||
/// Enable JSX transformation (0 = disabled, 1 = enabled)
|
||||
pub jsx_enabled: c_int,
|
||||
/// JSX development mode (0 = production, 1 = development)
|
||||
pub jsx_development: c_int,
|
||||
/// Enable TypeScript transformation (0 = disabled, 1 = enabled)
|
||||
pub typescript_enabled: c_int,
|
||||
/// Helper loader mode
|
||||
pub helper_loader_mode: TransformHelperLoaderMode,
|
||||
/// Target environment string (e.g., "es2020", "chrome58", null for default)
|
||||
/// This is a comma-separated list of targets
|
||||
pub target: *const c_char,
|
||||
}
|
||||
|
||||
/// Result structure for transformation operations
|
||||
#[repr(C)]
|
||||
pub struct TransformResult {
|
||||
/// Pointer to the transformed code (null-terminated C string)
|
||||
/// Caller is responsible for freeing this using `transformjs_free_string`
|
||||
pub output: *mut c_char,
|
||||
/// Length of the output string (excluding null terminator)
|
||||
pub output_len: usize,
|
||||
/// Error message if transformation failed (null-terminated C string)
|
||||
/// Caller is responsible for freeing this using `transformjs_free_string`
|
||||
pub error: *mut c_char,
|
||||
/// Success flag: 0 = success, non-zero = error
|
||||
pub success: c_int,
|
||||
}
|
||||
|
||||
/// Convert C options struct to Rust TransformOptions
|
||||
fn convert_options(c_options: Option<&CTransformOptions>) -> RustTransformOptions {
|
||||
if let Some(opts) = c_options {
|
||||
let mut rust_opts = if opts.jsx_enabled != 0 || opts.typescript_enabled != 0 {
|
||||
// If any options are set, start with defaults
|
||||
RustTransformOptions::default()
|
||||
} else {
|
||||
// If no options set, use enable_all for backward compatibility
|
||||
RustTransformOptions::enable_all()
|
||||
};
|
||||
|
||||
// Configure JSX
|
||||
if opts.jsx_enabled != 0 {
|
||||
rust_opts.jsx.development = opts.jsx_development != 0;
|
||||
} else {
|
||||
rust_opts.jsx.development = false;
|
||||
}
|
||||
|
||||
// Configure TypeScript - if disabled, clear TypeScript options
|
||||
if opts.typescript_enabled == 0 {
|
||||
// TypeScriptOptions is not publicly accessible, so we just leave it as default
|
||||
// The transformer will handle it appropriately
|
||||
}
|
||||
|
||||
// Configure helper loader mode
|
||||
rust_opts.helper_loader.mode = match opts.helper_loader_mode {
|
||||
TransformHelperLoaderMode::Runtime => HelperLoaderMode::Runtime,
|
||||
TransformHelperLoaderMode::External => HelperLoaderMode::External,
|
||||
};
|
||||
|
||||
// Configure target if provided
|
||||
if !opts.target.is_null() {
|
||||
if let Ok(target_str) = unsafe { CStr::from_ptr(opts.target) }.to_str() {
|
||||
if !target_str.is_empty() {
|
||||
if let Ok(env_opts) = oxc_transformer::EnvOptions::from_target(target_str) {
|
||||
rust_opts.env = env_opts;
|
||||
// Ensure module is set to CommonJS for bundling when target is specified
|
||||
rust_opts.env.module = Module::CommonJS;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Default to CommonJS module format for bundling
|
||||
rust_opts.env.module = Module::CommonJS;
|
||||
}
|
||||
|
||||
rust_opts
|
||||
} else {
|
||||
// Default: browser-compatible bundled output
|
||||
// Start with browser-compatible target (ES2020) which enables necessary transforms
|
||||
let mut opts = if let Ok(env_opts) = oxc_transformer::EnvOptions::from_target("es2020") {
|
||||
let mut base_opts = RustTransformOptions {
|
||||
env: env_opts,
|
||||
..RustTransformOptions::default()
|
||||
};
|
||||
// Enable all transformations for maximum browser compatibility
|
||||
base_opts.env = oxc_transformer::EnvOptions::enable_all(false);
|
||||
base_opts
|
||||
} else {
|
||||
RustTransformOptions::enable_all()
|
||||
};
|
||||
|
||||
// Set helper loader to Runtime to inline all helpers (bundled, no external dependencies)
|
||||
opts.helper_loader.mode = HelperLoaderMode::Runtime;
|
||||
|
||||
// Transform modules to CommonJS for bundling (browsers can't use ES modules directly)
|
||||
opts.env.module = Module::CommonJS;
|
||||
|
||||
// Production mode (not development)
|
||||
opts.jsx.development = false;
|
||||
|
||||
// Enable TypeScript transformation
|
||||
// (TypeScriptOptions::default() is already set)
|
||||
|
||||
// Enable decorators for full compatibility
|
||||
opts.decorator.legacy = true;
|
||||
opts.decorator.emit_decorator_metadata = true;
|
||||
|
||||
opts
|
||||
}
|
||||
}
|
||||
|
||||
/// Transform JavaScript/TypeScript source code
|
||||
///
|
||||
/// # Safety
|
||||
/// - `source` must be a valid null-terminated C string
|
||||
/// - `file_path` must be a valid null-terminated C string (can be null for default)
|
||||
/// - `options` can be null to use default options, or a pointer to a valid CTransformOptions struct
|
||||
/// - The caller is responsible for freeing the returned `TransformResult` using `transformjs_free_result`
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn transformjs_transform(
|
||||
source: *const c_char,
|
||||
file_path: *const c_char,
|
||||
options: *const CTransformOptions,
|
||||
) -> *mut TransformResult {
|
||||
let result = Box::new(TransformResult {
|
||||
output: std::ptr::null_mut(),
|
||||
output_len: 0,
|
||||
error: std::ptr::null_mut(),
|
||||
success: 1,
|
||||
});
|
||||
|
||||
if source.is_null() {
|
||||
let error_msg = CString::new("source is null").unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_msg.into_raw();
|
||||
result.success = 1;
|
||||
return Box::into_raw(result);
|
||||
}
|
||||
|
||||
let source_str = match unsafe { CStr::from_ptr(source) }.to_str() {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
let error_msg = CString::new(format!("Invalid UTF-8 in source: {}", e)).unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_msg.into_raw();
|
||||
result.success = 1;
|
||||
return Box::into_raw(result);
|
||||
}
|
||||
};
|
||||
|
||||
let path = if file_path.is_null() {
|
||||
Path::new("input.js")
|
||||
} else {
|
||||
match unsafe { CStr::from_ptr(file_path) }.to_str() {
|
||||
Ok(s) => Path::new(s),
|
||||
Err(_) => Path::new("input.js"),
|
||||
}
|
||||
};
|
||||
|
||||
let allocator = Allocator::default();
|
||||
let source_type = SourceType::from_path(path).unwrap_or(SourceType::default());
|
||||
|
||||
// Parse
|
||||
let ret = Parser::new(&allocator, source_str, source_type).parse();
|
||||
|
||||
if !ret.errors.is_empty() {
|
||||
let error_msg = format!("Parser errors: {} errors found", ret.errors.len());
|
||||
let error_cstr = CString::new(error_msg).unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_cstr.into_raw();
|
||||
result.success = 1;
|
||||
return Box::into_raw(result);
|
||||
}
|
||||
|
||||
let mut program = ret.program;
|
||||
|
||||
// Build semantic information
|
||||
let ret = SemanticBuilder::new()
|
||||
.with_excess_capacity(2.0)
|
||||
.build(&program);
|
||||
|
||||
if !ret.errors.is_empty() {
|
||||
let error_msg = format!("Semantic errors: {} errors found", ret.errors.len());
|
||||
let error_cstr = CString::new(error_msg).unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_cstr.into_raw();
|
||||
result.success = 1;
|
||||
return Box::into_raw(result);
|
||||
}
|
||||
|
||||
let scoping = ret.semantic.into_scoping();
|
||||
|
||||
// Convert C options to Rust TransformOptions
|
||||
let c_options = if options.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { &*options })
|
||||
};
|
||||
let transform_options = convert_options(c_options);
|
||||
|
||||
// Transform
|
||||
let ret = Transformer::new(&allocator, path, &transform_options)
|
||||
.build_with_scoping(scoping, &mut program);
|
||||
|
||||
if !ret.errors.is_empty() {
|
||||
let error_msg = format!("Transformer errors: {} errors found", ret.errors.len());
|
||||
let error_cstr = CString::new(error_msg).unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_cstr.into_raw();
|
||||
result.success = 1;
|
||||
return Box::into_raw(result);
|
||||
}
|
||||
|
||||
// Generate code
|
||||
let printed = Codegen::new().build(&program).code;
|
||||
|
||||
match CString::new(printed) {
|
||||
Ok(output_cstr) => {
|
||||
let output_len = output_cstr.as_bytes().len();
|
||||
let mut result = result;
|
||||
result.output = output_cstr.into_raw();
|
||||
result.output_len = output_len;
|
||||
result.success = 0;
|
||||
Box::into_raw(result)
|
||||
}
|
||||
Err(e) => {
|
||||
let error_msg = CString::new(format!("Failed to create output string: {}", e)).unwrap();
|
||||
let mut result = result;
|
||||
result.error = error_msg.into_raw();
|
||||
result.success = 1;
|
||||
Box::into_raw(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Free a string allocated by the library
|
||||
///
|
||||
/// # Safety
|
||||
/// - `ptr` must be a pointer returned by the library, or null
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn transformjs_free_string(ptr: *mut c_char) {
|
||||
if !ptr.is_null() {
|
||||
let _ = unsafe { CString::from_raw(ptr) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Free a TransformResult structure
|
||||
///
|
||||
/// # Safety
|
||||
/// - `result` must be a pointer returned by `transformjs_transform`, or null
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn transformjs_free_result(result: *mut TransformResult) {
|
||||
if !result.is_null() {
|
||||
let result = unsafe { Box::from_raw(result) };
|
||||
if !result.output.is_null() {
|
||||
let _ = unsafe { CString::from_raw(result.output) };
|
||||
}
|
||||
if !result.error.is_null() {
|
||||
let _ = unsafe { CString::from_raw(result.error) };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,112 +0,0 @@
|
||||
/* TransformJS C Bindings - Generated by cbindgen */
|
||||
|
||||
#ifndef TRANSFORMJS_H
|
||||
#define TRANSFORMJS_H
|
||||
|
||||
/* Generated with cbindgen:0.29.2 */
|
||||
|
||||
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Helper loader mode
|
||||
*/
|
||||
typedef enum TransformHelperLoaderMode {
|
||||
/**
|
||||
* Runtime mode - helpers are inlined
|
||||
*/
|
||||
TransformHelperLoaderMode_Runtime = 0,
|
||||
/**
|
||||
* External mode - helpers are imported
|
||||
*/
|
||||
TransformHelperLoaderMode_External = 1,
|
||||
} TransformHelperLoaderMode;
|
||||
|
||||
/**
|
||||
* Transform options structure (C-compatible)
|
||||
*/
|
||||
typedef struct CTransformOptions {
|
||||
/**
|
||||
* Enable JSX transformation (0 = disabled, 1 = enabled)
|
||||
*/
|
||||
int jsx_enabled;
|
||||
/**
|
||||
* JSX development mode (0 = production, 1 = development)
|
||||
*/
|
||||
int jsx_development;
|
||||
/**
|
||||
* Enable TypeScript transformation (0 = disabled, 1 = enabled)
|
||||
*/
|
||||
int typescript_enabled;
|
||||
/**
|
||||
* Helper loader mode
|
||||
*/
|
||||
TransformHelperLoaderMode helper_loader_mode;
|
||||
/**
|
||||
* Target environment string (e.g., "es2020", "chrome58", null for default)
|
||||
* This is a comma-separated list of targets
|
||||
*/
|
||||
const char *target;
|
||||
} CTransformOptions;
|
||||
|
||||
/**
|
||||
* Result structure for transformation operations
|
||||
*/
|
||||
typedef struct TransformResult {
|
||||
/**
|
||||
* Pointer to the transformed code (null-terminated C string)
|
||||
* Caller is responsible for freeing this using `transformjs_free_string`
|
||||
*/
|
||||
char *output;
|
||||
/**
|
||||
* Length of the output string (excluding null terminator)
|
||||
*/
|
||||
size_t output_len;
|
||||
/**
|
||||
* Error message if transformation failed (null-terminated C string)
|
||||
* Caller is responsible for freeing this using `transformjs_free_string`
|
||||
*/
|
||||
char *error;
|
||||
/**
|
||||
* Success flag: 0 = success, non-zero = error
|
||||
*/
|
||||
int success;
|
||||
} TransformResult;
|
||||
|
||||
/**
|
||||
* Transform JavaScript/TypeScript source code
|
||||
*
|
||||
* # Safety
|
||||
* - `source` must be a valid null-terminated C string
|
||||
* - `file_path` must be a valid null-terminated C string (can be null for default)
|
||||
* - `options` can be null to use default options, or a pointer to a valid CTransformOptions struct
|
||||
* - The caller is responsible for freeing the returned `TransformResult` using `transformjs_free_result`
|
||||
*/
|
||||
struct TransformResult *transformjs_transform(const char *source,
|
||||
const char *file_path,
|
||||
const struct CTransformOptions *options);
|
||||
|
||||
/**
|
||||
* Free a string allocated by the library
|
||||
*
|
||||
* # Safety
|
||||
* - `ptr` must be a pointer returned by the library, or null
|
||||
*/
|
||||
void transformjs_free_string(char *ptr);
|
||||
|
||||
/**
|
||||
* Free a TransformResult structure
|
||||
*
|
||||
* # Safety
|
||||
* - `result` must be a pointer returned by `transformjs_transform`, or null
|
||||
*/
|
||||
void transformjs_free_result(struct TransformResult *result);
|
||||
|
||||
#endif /* TRANSFORMJS_H */
|
||||
@ -1,5 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const rustlib = @import("rust.zig");
|
||||
pub const initlib = @import("init.zig");
|
||||
pub const plugins = @import("plugins.zig");
|
||||
@ -1,15 +0,0 @@
|
||||
//! Plugins are experimental and will change in the future
|
||||
//! // TODO: Plugin should always be a file with main() function that receiveds standaridized args
|
||||
// Maybe there can be stdio mode where files will be provided in zon format line by line
|
||||
pub const tailwind = @import("plugins/tailwind.zig").tailwind;
|
||||
pub const esbuild = @import("plugins/esbuild.zig").esbuild;
|
||||
pub const Bun = @import("plugins/Bun.zig");
|
||||
|
||||
pub fn PluginCtx(opts: type) type {
|
||||
return struct {
|
||||
options: opts,
|
||||
build: *std.Build,
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
@ -1,51 +0,0 @@
|
||||
const Bun = @This();
|
||||
|
||||
pub fn init(ctx: plugin.PluginCtx(BunPluginOptions)) InitOptions.PluginOptions {
|
||||
const options = ctx.options;
|
||||
const b = ctx.build;
|
||||
|
||||
var cmd = b.addSystemCommand(&.{ "bun", options.sub_cmd });
|
||||
for (options.inputs) |input| {
|
||||
cmd.addFileArg(input);
|
||||
cmd.addFileInput(input);
|
||||
}
|
||||
|
||||
if (options.outdir) |outdir| {
|
||||
cmd.addPrefixedDirectoryArg("--outdir=", outdir);
|
||||
}
|
||||
|
||||
if (options.sourcemap) |sourcemap| {
|
||||
cmd.addArg("--sourcemap");
|
||||
cmd.addArg(@tagName(sourcemap));
|
||||
}
|
||||
|
||||
const steps = b.allocator.alloc(InitOptions.PluginOptions.PluginStep, 1) catch @panic("OOM");
|
||||
steps[0] = .{
|
||||
.command = .{
|
||||
.type = .after_transpile,
|
||||
.run = cmd,
|
||||
},
|
||||
};
|
||||
|
||||
return .{
|
||||
.name = "bun",
|
||||
.steps = steps,
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const LazyPath = std.Build.LazyPath;
|
||||
|
||||
const BunPluginOptions = struct {
|
||||
pub const Sourcemap = enum { linked, @"inline", external, none };
|
||||
|
||||
bin: ?LazyPath = null,
|
||||
sub_cmd: []const u8 = "build",
|
||||
inputs: []const LazyPath = &.{},
|
||||
outdir: ?LazyPath = null,
|
||||
sourcemap: ?Sourcemap = null,
|
||||
};
|
||||
|
||||
const InitOptions = @import("../init/InitOptions.zig");
|
||||
const plugin = @import("../plugins.zig");
|
||||
@ -1,17 +0,0 @@
|
||||
pub fn plugin(ctx: p.PluginCtx(PluginArgs)) !void {
|
||||
_ = ctx;
|
||||
}
|
||||
|
||||
pub const PluginArgs = struct {
|
||||
@"--bundle": bool,
|
||||
variadic: bool,
|
||||
};
|
||||
pub const options: PluginOptions = .{
|
||||
.name = "bun",
|
||||
};
|
||||
|
||||
const PluginOptions = struct {
|
||||
name: []const u8,
|
||||
};
|
||||
|
||||
const p = @import("../../plugins.zig");
|
||||
@ -1,131 +0,0 @@
|
||||
pub fn esbuild(b: *std.Build, options: EsbuildPluginOptions) InitOptions.PluginOptions {
|
||||
const bin = options.bin orelse b.path("node_modules/.bin/esbuild");
|
||||
const input = options.input orelse b.path("app/main.ts");
|
||||
const output = options.output orelse b.path("{outdir}/assets/main.js");
|
||||
|
||||
const cmd: *std.Build.Step.Run = .create(b, "esbuild");
|
||||
cmd.addFileArg(bin);
|
||||
cmd.addFileArg(input);
|
||||
|
||||
if (options.bundle) {
|
||||
cmd.addArg("--bundle");
|
||||
}
|
||||
|
||||
cmd.addPrefixedFileArg("--outfile=", output);
|
||||
|
||||
if (options.log_level) |log_level| {
|
||||
cmd.addArg(b.fmt("--log-level={s}", .{@tagName(log_level)}));
|
||||
}
|
||||
|
||||
if (options.format) |format| {
|
||||
cmd.addArg(b.fmt("--format={s}", .{@tagName(format)}));
|
||||
}
|
||||
|
||||
if (options.platform) |platform| {
|
||||
cmd.addArg(b.fmt("--platform={s}", .{@tagName(platform)}));
|
||||
}
|
||||
|
||||
if (options.target) |target| {
|
||||
cmd.addArg(b.fmt("--target={s}", .{target}));
|
||||
}
|
||||
|
||||
if (options.splitting) {
|
||||
cmd.addArg("--splitting");
|
||||
}
|
||||
|
||||
for (options.external) |ext| {
|
||||
cmd.addArg(b.fmt("--external:{s}", .{ext}));
|
||||
}
|
||||
|
||||
// Handle minify/sourcemap based on build mode or explicit options
|
||||
const is_debug = options.optimize == .Debug;
|
||||
const is_release = !is_debug;
|
||||
|
||||
if (options.minify orelse is_release) {
|
||||
cmd.addArg("--minify");
|
||||
}
|
||||
|
||||
if (options.sourcemap) |sm|
|
||||
switch (sm) {
|
||||
.@"inline" => cmd.addArg("--sourcemap=inline"),
|
||||
.external => cmd.addArg("--sourcemap=external"),
|
||||
.linked => cmd.addArg("--sourcemap=linked"),
|
||||
.both => cmd.addArg("--sourcemap=both"),
|
||||
}
|
||||
else if (is_debug)
|
||||
cmd.addArg("--sourcemap=inline");
|
||||
|
||||
// Add define based on build mode
|
||||
if (is_release) {
|
||||
cmd.addArgs(&.{
|
||||
"--define:__DEV__=false",
|
||||
"--define:process.env.NODE_ENV=\"production\"",
|
||||
});
|
||||
} else {
|
||||
cmd.addArgs(&.{
|
||||
"--define:__DEV__=true",
|
||||
"--define:process.env.NODE_ENV=\"development\"",
|
||||
});
|
||||
}
|
||||
|
||||
// Add custom defines
|
||||
for (options.define) |def| {
|
||||
cmd.addArg(b.fmt("--define:{s}={s}", .{ def.key, def.value }));
|
||||
}
|
||||
|
||||
const steps = b.allocator.alloc(InitOptions.PluginOptions.PluginStep, 1) catch @panic("OOM");
|
||||
steps[0] = .{
|
||||
.command = .{
|
||||
.type = .after_transpile,
|
||||
.run = cmd,
|
||||
},
|
||||
};
|
||||
|
||||
return .{
|
||||
.name = "esbuild",
|
||||
.steps = steps,
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const LazyPath = std.Build.LazyPath;
|
||||
|
||||
const EsbuildPluginOptions = struct {
|
||||
/// Path to the esbuild binary [default: `node_modules/.bin/esbuild`]
|
||||
bin: ?LazyPath = null,
|
||||
/// Input entry point file [default: `app/main.ts`]
|
||||
input: ?LazyPath = null,
|
||||
/// Output file [default: `{outdir}/assets/main.js`]
|
||||
/// `{outdir}/assets` means you can link the script like:
|
||||
/// ```html
|
||||
/// <script src="/assets/main.js"></script>
|
||||
/// ```
|
||||
output: ?LazyPath = null,
|
||||
/// Bundle all dependencies into the output files [default: `true`]
|
||||
bundle: bool = true,
|
||||
/// Minify the output (sets all --minify-* flags) [default: `true` in release, `false` in debug]
|
||||
minify: ?bool = null,
|
||||
/// Emit a source map [default: `inline` in debug, `none` in release]
|
||||
sourcemap: ?enum { @"inline", external, linked, both } = null,
|
||||
/// Disable logging [default: `silent`]
|
||||
log_level: ?enum { verbose, debug, info, warning, @"error", silent } = .@"error",
|
||||
/// Output format [default: inferred by esbuild]
|
||||
format: ?enum { iife, cjs, esm } = null,
|
||||
/// Platform target [default: `browser`]
|
||||
platform: ?enum { browser, node, neutral } = null,
|
||||
/// Environment target (e.g. es2017, chrome58, node10) [default: `esnext`]
|
||||
target: ?[]const u8 = null,
|
||||
/// Enable code splitting (currently only for esm)
|
||||
splitting: bool = false,
|
||||
/// Exclude modules from the bundle (can use * wildcards)
|
||||
external: []const []const u8 = &.{},
|
||||
/// Substitute K with V while parsing (in addition to __DEV__ and process.env.NODE_ENV)
|
||||
define: []const struct { key: []const u8, value: []const u8 } = &.{},
|
||||
|
||||
// watch: bool = false, // Available with esbuild, but zig watch already handles rebuilding
|
||||
|
||||
optimize: ?std.builtin.OptimizeMode = null,
|
||||
};
|
||||
|
||||
const InitOptions = @import("../init/InitOptions.zig");
|
||||
@ -1,81 +0,0 @@
|
||||
pub fn tailwind(b: *std.Build, options: TailwindPluginOptions) InitOptions.PluginOptions {
|
||||
const bin = options.bin orelse b.path("node_modules/.bin/tailwindcss");
|
||||
const input = options.input orelse b.path("app/assets/styles.css");
|
||||
const output = options.output orelse b.path("{outdir}/assets/styles.css");
|
||||
|
||||
const cmd: *std.Build.Step.Run = .create(b, "tailwind");
|
||||
cmd.addFileArg(bin);
|
||||
|
||||
cmd.addArg("-i");
|
||||
cmd.addFileArg(input);
|
||||
|
||||
cmd.addArg("-o");
|
||||
cmd.addFileArg(output);
|
||||
|
||||
// This option is available with the tailwindcss CLI, but since zig watch already handles it we are not allowing it
|
||||
// if (options.watch) |watch| {
|
||||
// switch (watch) {
|
||||
// .enabled => cmd.addArg("--watch"),
|
||||
// .always => cmd.addArg("--watch=always"),
|
||||
// }
|
||||
// }
|
||||
|
||||
if (options.minify) {
|
||||
cmd.addArg("--minify");
|
||||
}
|
||||
|
||||
if (options.optimize) {
|
||||
cmd.addArg("--optimize");
|
||||
}
|
||||
|
||||
if (options.cwd) |cwd| {
|
||||
cmd.addArg("--cwd");
|
||||
cmd.addFileArg(cwd);
|
||||
}
|
||||
|
||||
if (options.map) {
|
||||
cmd.addArg("--map");
|
||||
}
|
||||
|
||||
const steps = b.allocator.alloc(InitOptions.PluginOptions.PluginStep, 1) catch @panic("OOM");
|
||||
steps[0] = .{
|
||||
.command = .{
|
||||
.type = .after_transpile,
|
||||
.run = cmd,
|
||||
},
|
||||
};
|
||||
|
||||
return .{
|
||||
.name = "tailwindcss",
|
||||
.steps = steps,
|
||||
};
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
const LazyPath = std.Build.LazyPath;
|
||||
|
||||
const TailwindPluginOptions = struct {
|
||||
/// Path to the tailwindcss binary [default: `node_modules/.bin/tailwindcss`]
|
||||
bin: ?LazyPath = null,
|
||||
/// Input file [default: `app/assets/styles.css`]
|
||||
input: ?LazyPath = null,
|
||||
/// Output file [default: `{outdir}/assets/styles.css`]
|
||||
/// `{outdir}/assets` means you can add link the styles like
|
||||
/// ```html
|
||||
/// <link rel="stylesheet" href="/assets/styles.css" />
|
||||
/// ```
|
||||
output: ?LazyPath = null,
|
||||
|
||||
// watch: ?enum { enabled, always } = null, // This option is available with the tailwindcss CLI, but since zig watch already handles it we are not allowing it
|
||||
|
||||
/// Optimize and minify the output
|
||||
minify: bool = false,
|
||||
/// Optimize the output without minifying
|
||||
optimize: bool = false,
|
||||
/// The current working directory [default: `.`]
|
||||
cwd: ?LazyPath = null,
|
||||
/// Generate a source map [default: `false`]
|
||||
map: bool = false,
|
||||
};
|
||||
|
||||
const InitOptions = @import("../init/InitOptions.zig");
|
||||
@ -1,93 +0,0 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Build the TransformJS Rust library as a C dynamic library
|
||||
/// Returns a build step that must be completed before linking
|
||||
pub fn build(
|
||||
b: *std.Build,
|
||||
target: std.Build.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
) *std.Build.Step {
|
||||
const transformjs_dir = "pkg/transformjs";
|
||||
|
||||
// Build the Rust library using cargo
|
||||
const cargo_build = b.addSystemCommand(&.{ "cargo", "build", "--lib" });
|
||||
cargo_build.setCwd(b.path(transformjs_dir));
|
||||
|
||||
if (optimize == .ReleaseFast or optimize == .ReleaseSafe or optimize == .ReleaseSmall) {
|
||||
cargo_build.addArg("--release");
|
||||
}
|
||||
|
||||
// Convert Zig target to Rust target triple for cross-compilation
|
||||
const rust_target = toRustTarget(target.result);
|
||||
if (rust_target) |triple| {
|
||||
cargo_build.addArg("--target");
|
||||
cargo_build.addArg(triple);
|
||||
}
|
||||
|
||||
return &cargo_build.step;
|
||||
}
|
||||
|
||||
/// Convert Zig target to Rust target triple
|
||||
/// Returns null for native target (cargo default)
|
||||
fn toRustTarget(target: std.Target) ?[]const u8 {
|
||||
const builtin = @import("builtin");
|
||||
const is_native = target.os.tag == builtin.target.os.tag and
|
||||
target.cpu.arch == builtin.target.cpu.arch;
|
||||
|
||||
if (is_native) {
|
||||
return null; // Use cargo default (native target)
|
||||
}
|
||||
|
||||
// Convert to Rust target triple format
|
||||
return switch (target.os.tag) {
|
||||
.linux => switch (target.cpu.arch) {
|
||||
.x86_64 => "x86_64-unknown-linux-gnu",
|
||||
.aarch64 => "aarch64-unknown-linux-gnu",
|
||||
else => null,
|
||||
},
|
||||
.macos => switch (target.cpu.arch) {
|
||||
.x86_64 => "x86_64-apple-darwin",
|
||||
.aarch64 => "aarch64-apple-darwin",
|
||||
else => null,
|
||||
},
|
||||
.windows => switch (target.cpu.arch) {
|
||||
.x86_64 => "x86_64-pc-windows-msvc",
|
||||
.aarch64 => "aarch64-pc-windows-msvc",
|
||||
else => null,
|
||||
},
|
||||
else => null, // Unsupported OS
|
||||
};
|
||||
}
|
||||
|
||||
pub fn link(
|
||||
b: *std.Build,
|
||||
exe: *std.Build.Step.Compile,
|
||||
build_step: *std.Build.Step,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
) void {
|
||||
const target = exe.root_module.resolved_target orelse return;
|
||||
const transformjs_dir = "pkg/transformjs";
|
||||
|
||||
exe.step.dependOn(build_step);
|
||||
exe.addIncludePath(b.path(transformjs_dir));
|
||||
|
||||
// Determine library directory - cargo puts cross-compiled libs in target/<triple>/<profile>
|
||||
const rust_target_triple = toRustTarget(target.result);
|
||||
const lib_dir = if (optimize == .ReleaseFast or optimize == .ReleaseSafe or optimize == .ReleaseSmall)
|
||||
if (rust_target_triple) |triple|
|
||||
b.pathJoin(&.{ transformjs_dir, "target", triple, "release" })
|
||||
else
|
||||
b.pathJoin(&.{ transformjs_dir, "target", "release" })
|
||||
else if (rust_target_triple) |triple|
|
||||
b.pathJoin(&.{ transformjs_dir, "target", triple, "debug" })
|
||||
else
|
||||
b.pathJoin(&.{ transformjs_dir, "target", "debug" });
|
||||
|
||||
exe.addLibraryPath(b.path(lib_dir));
|
||||
exe.linkSystemLibrary("transformjs");
|
||||
exe.linkSystemLibrary("c");
|
||||
|
||||
if (target.result.os.tag != .windows) {
|
||||
exe.linkSystemLibrary("dl");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user