pcbjam/wasm/cli/sym_convert_main.cpp
Gergő Törcsvári 698f6d7cb7
feat(libs): standalone .lib→.kicad_sym wasm converter (sym_convert)
Headless node-WASM CLI that converts legacy symbol libraries to .kicad_sym via
SCH_IO_MGR::ConvertLibrary. Adds wasm/cli/sym_convert_main.cpp + sym_convert_pre.js
(in-memory localStorage + wxConfig JS-hook shim), registers sym_convert as a
docker/build.sh app (own kicad-sym_convert tree, real wasm-opt/finalize in-container,
skip host postprocess), and bumps the kicad pointer for the matching target.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 12:21:15 +02:00

61 lines
2.1 KiB
C++

/*
* sym_convert — standalone CLI for legacy (.lib) -> S-expression (.kicad_sym)
* symbol-library conversion, built as a WebAssembly module.
*
* It drives SCH_IO_MGR::ConvertLibrary directly from main(): no GUI, no
* renderer, no embind bindings, no JS host logic. Wired into
* eeschema/CMakeLists.txt behind the KICAD_SYM_CONVERTER_WASM option
* (see scripts/kicad/build-sym-convert-wasm.sh).
*
* Targets:
* - Node: built with -sENVIRONMENT=node -sNODERAWFS=1 (the default here);
* run with `node sym_convert.js in.lib out.kicad_sym`.
* - wasmtime: a follow-up build (no pthreads, -sSTANDALONE_WASM) lets the
* same code run host-less under `wasmtime sym_convert.wasm ...`.
*
* GPL note: this is GPL KiCad code. The artifact is meant to be invoked as a
* separate process from the closed ingester, never linked into closed code.
*/
#include <cstdio>
#include <wx/init.h>
#include <wx/string.h>
#include <sch_io/sch_io_mgr.h>
int main( int argc, char** argv )
{
if( argc < 3 )
{
std::fprintf( stderr, "usage: sym_convert <input.lib> <output.kicad_sym>\n" );
return 2;
}
// Bring up wxBase (no GUI): wxString / wxFileName / wxFFile rely on the
// library being initialised. If the conversion path turns out to need more
// global state (PGM_BASE, settings), the run will surface it here.
wxInitializer initializer( argc, argv );
if( !initializer.IsOk() )
{
std::fprintf( stderr, "sym_convert: wxWidgets initialisation failed\n" );
return 3;
}
const wxString inPath = wxString::FromUTF8( argv[1] );
const wxString outPath = wxString::FromUTF8( argv[2] );
// aOldFileProps = nullptr: no library-table properties; ConvertLibrary
// guesses the source format from the path and writes the SCH_KICAD format.
const bool ok = SCH_IO_MGR::ConvertLibrary( nullptr, inPath, outPath );
if( ok )
{
std::fprintf( stderr, "sym_convert: OK %s -> %s\n", argv[1], argv[2] );
return 0;
}
std::fprintf( stderr, "sym_convert: FAILED to convert %s\n", argv[1] );
return 1;
}