Skip to content

Commit

Permalink
add webassembly support to chuginate; add ck_info to chuginate templa…
Browse files Browse the repository at this point in the history
…te; 1.5.2.1 chugin.h
  • Loading branch information
gewang committed Jan 17, 2024
1 parent f6dbf26 commit 7802a19
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 52 deletions.
23 changes: 16 additions & 7 deletions chuck/include/chugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
// 1.5.0.0 (ge) | moved to chuck.h for at-a-glance visibility
// 1.5.2.0 (ge) | moved to chuck_def.h for chugins headers streamlining
//-----------------------------------------------------------------------------
#define CHUCK_VERSION_STRING "1.5.2.0 (chai)"
#define CHUCK_VERSION_STRING "1.5.2.1 (chai)"
//-----------------------------------------------------------------------------


Expand Down Expand Up @@ -1336,6 +1336,8 @@ typedef const Chuck_DL_Api * CK_DL_API;
// macro for declaring version of ChucK DL a given DLL links to
// example: CK_DLL_DECLVERSION
#define CK_DLL_DECLVERSION CK_DLL_EXPORT(t_CKUINT) ck_version() { return CK_DLL_VERSION; }
// macro for defining a DLL info func
#define CK_DLL_INFO(name) CK_DLL_EXPORT(void) ck_info( Chuck_DL_Query * QUERY )
// naming convention for static query functions
#define CK_DLL_QUERY_STATIC_NAME(name) ck_##name##_query
// macro for defining ChucK DLL export query-functions (static version)
Expand Down Expand Up @@ -1409,7 +1411,7 @@ typedef const Chuck_DL_Api * CK_DL_API;
extern "C" {
// query
typedef t_CKUINT (CK_DLL_CALL * f_ck_declversion)();
typedef const char * (CK_DLL_CALL * f_ck_info)( const char * key );
typedef t_CKVOID (CK_DLL_CALL * f_ck_info)( Chuck_DL_Query * QUERY );
typedef t_CKBOOL (CK_DLL_CALL * f_ck_query)( Chuck_DL_Query * QUERY );
// object
typedef Chuck_Object * (CK_DLL_CALL * f_alloc)( Chuck_VM * VM, Chuck_VM_Shred * SHRED, CK_DL_API API );
Expand Down Expand Up @@ -1439,10 +1441,12 @@ typedef void (CK_DLL_CALL * f_callback_on_instantiate)( Chuck_Object * OBJECT, C
}


// default name in DLL/ckx to look for
#define CK_QUERY_FUNC "ck_query"
// default name in DLL/ckx to look for
#define CK_DECLVERSION_FUNC "ck_version"
// default name in DLL/ckx to look for host/chugin compatibility version func
#define CK_DECLVERSION_FUNC "ck_version"
// default name in DLL/ckx to look for info func
#define CK_INFO_FUNC "ck_info"
// default name in DLL/ckx to look for for query func
#define CK_QUERY_FUNC "ck_query"
// bad object data offset
#define CK_INVALID_OFFSET 0xffffffff

Expand Down Expand Up @@ -2197,10 +2201,11 @@ struct Chuck_DL_Api
struct Chuck_DLL /* : public Chuck_VM_Object */
{
public:
// load dynamic ckx/dll from filename
// load module (chugin/dll) from filename
t_CKBOOL load( const char * filename,
const char * func = CK_QUERY_FUNC,
t_CKBOOL lazy = FALSE );
// load module (internal) from query func
t_CKBOOL load( f_ck_query query_func, t_CKBOOL lazy = FALSE );
// get address in loaded ckx
void * get_addr( const char * symbol );
Expand All @@ -2227,6 +2232,10 @@ struct Chuck_DLL /* : public Chuck_VM_Object */
// chugin minor version must less than or equal host minor version
t_CKBOOL compatible();

public:
// get info from query
std::string getinfo( const std::string & key );

public:
// constructor
Chuck_DLL( Chuck_Carrier * carrier, const char * xid = NULL )
Expand Down
64 changes: 39 additions & 25 deletions chuginate/chuginate

Large diffs are not rendered by default.

30 changes: 17 additions & 13 deletions chuginate/template/ChuGin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,33 @@ class %(CHUGIN_NAME)%


//-----------------------------------------------------------------------------
// query function: ChucK calls this when loading the chugin
// modify this function to define this chugin's API and language extensions
// info function: ChucK calls this when loading/probing the chugin
// NOTE: please customize these info fields below; they will be used for
// chugins loading, probing, and package management and documentation
//-----------------------------------------------------------------------------
CK_DLL_QUERY( %(CHUGIN_NAME)% )
CK_DLL_INFO( %(CHUGIN_NAME)% )
{
// generally, don't change this...
QUERY->setname( QUERY, "%(CHUGIN_NAME)%" );

// ------------------------------------------------------------------------
// please DO customize these info fields below; they will be
// used for chugins package management and documentation
// ------------------------------------------------------------------------
// the version string of this chugin, e.g., "v1.2.1"
QUERY->setinfo( QUERY, CHUGIN_INFO_CHUGIN_VERSION, "" );
// the author(s) of this chugin, e.g., "Alice Baker & Carl Donut"
QUERY->setinfo( QUERY, CHUGIN_INFO_AUTHORS, "" );
// the version string of this chugin, e.g., "v1.2"
QUERY->setinfo( QUERY, CHUGIN_INFO_CHUGIN_VERSION, "" );
// text description of this chugin; what is it? what does it do? who is it for?
QUERY->setinfo( QUERY, CHUGIN_INFO_DESCRIPTION, "" );
// (optional) URL of the homepage for this chugin
QUERY->setinfo( QUERY, CHUGIN_INFO_URL, "" );
// (optional) contact email
QUERY->setinfo( QUERY, CHUGIN_INFO_EMAIL, "" );
// ------------------------------------------------------------------------
}


//-----------------------------------------------------------------------------
// query function: ChucK calls this when loading the chugin
// modify this function to define this chugin's API and language extensions
//-----------------------------------------------------------------------------
CK_DLL_QUERY( %(CHUGIN_NAME)% )
{
// generally, don't change this...
QUERY->setname( QUERY, "%(CHUGIN_NAME)%" );

// ------------------------------------------------------------------------
// begin class definition(s); will be compiled, verified,
Expand Down
24 changes: 17 additions & 7 deletions chuginate/template/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CHUGIN_NAME=%(CHUGIN_NAME)%
C_MODULES=
CXX_MODULES=%(CHUGIN_NAME)%.cpp

# where the chuck headers are
# where to find chugin.h
CK_SRC_PATH?=%(CHUGIN_HEADER_PATH)%

# where to install chugin
Expand All @@ -19,8 +19,8 @@ CHUGIN_PATH?=/usr/local/lib/chuck

# default target: print usage message and quit
current:
@echo "[chuck build]: please use one of the following configurations:"
@echo " make linux, make mac, or make win32"
@echo "[chugin build]: please use one of the following configurations:"
@echo " make linux, make mac, make web, or make win32"

ifneq ($(CK_TARGET),)
.DEFAULT_GOAL:=$(CK_TARGET)
Expand All @@ -39,7 +39,7 @@ CC=gcc
CXX=gcc
LD=g++

ifneq (,$(strip $(filter osx mac,$(MAKECMDGOALS))))
ifneq (,$(strip $(filter mac osx,$(MAKECMDGOALS))))
include makefile.mac
endif

Expand All @@ -51,6 +51,10 @@ ifneq (,$(strip $(filter linux-oss,$(MAKECMDGOALS))))
include makefile.linux
endif

ifneq (,$(strip $(filter linux-pulse,$(MAKECMDGOALS))))
include makefile.linux
endif

ifneq (,$(strip $(filter linux-jack,$(MAKECMDGOALS))))
include makefile.linux
endif
Expand All @@ -69,7 +73,6 @@ ifneq ($(CHUCK_STRICT),)
FLAGS+= -Werror
endif


# default: build a dynamic chugin
CK_CHUGIN_STATIC?=0

Expand All @@ -79,11 +82,14 @@ else
SUFFIX=.schug
FLAGS+= -D__CK_DLL_STATIC__
endif
# webchugin extension
WEBSUFFIX=.wasm

C_OBJECTS=$(addsuffix .o,$(basename $(C_MODULES)))
CXX_OBJECTS=$(addsuffix .o,$(basename $(CXX_MODULES)))

CHUG=$(addsuffix $(SUFFIX),$(CHUGIN_NAME))
WEBCHUG=$(addsuffix $(WEBSUFFIX),$(CHUG))

all: $(CHUG)

Expand All @@ -101,11 +107,15 @@ $(C_OBJECTS): %.o: %.c
$(CXX_OBJECTS): %.o: %.cpp $(CK_SRC_PATH)/chugin.h
$(CXX) $(FLAGS) -c -o $@ $<

# build as webchugin
web:
emcc -O3 -s SIDE_MODULE=1 -s DISABLE_EXCEPTION_CATCHING=0 -fPIC -Wformat=0 \
-I $(CK_SRC_PATH) $(CXX_MODULES) $(C_MODULES) -o $(WEBCHUG)

install: $(CHUG)
mkdir -p $(CHUGIN_PATH)
cp $^ $(CHUGIN_PATH)
chmod 755 $(CHUGIN_PATH)/$(CHUG)

clean:
rm -rf $(C_OBJECTS) $(CXX_OBJECTS) $(CHUG) Release Debug

rm -rf $(C_OBJECTS) $(CXX_OBJECTS) $(CHUG) $(WEBCHUG) Release Debug

0 comments on commit 7802a19

Please sign in to comment.