Skip to content

Commit

Permalink
chore: re-compile lua with generic WASM and add 32-bit support #990
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterFarber committed Sep 26, 2024
1 parent 9ed6347 commit ab31154
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
14 changes: 14 additions & 0 deletions dev-cli/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
RUN node --version
RUN npm --version

# Make a copy of the lua runtime for 32-bit
RUN cp -r /lua-${LUA_VERSION} /lua-${LUA_VERSION}-32

# And, re-compile lua with "generic WASM"
RUN cd /lua-${LUA_VERSION} && \
make clean && \
make generic CC='emcc -s WASM=1 -s MEMORY64=1 -s SUPPORT_LONGJMP=1'

# And, re-compile lua with "generic WASM 32-bit"
RUN cd /lua-${LUA_VERSION}-32 && \
make clean && \
make generic CC='emcc -s WASM=1 -s SUPPORT_LONGJMP=1'


#############################
##### Install Commands ######
#############################
Expand Down Expand Up @@ -91,6 +100,11 @@ RUN chmod +x /usr/local/bin/ao-build-module
# BUILD WeaveDrive Extension Helper
###################################
COPY ./src/aolibc /opt/aolibc
## Build aolibc for 32-bit and rename to aolibc32
RUN cd /opt/aolibc && make CC="emcc -s WASM=1 -s SUPPORT_LONGJMP=1" && cp ./aolibc.a ./aolibc32.a
RUN rm /opt/aolibc/aolibc.a
RUN rm /opt/aolibc/aostdio.o
# Build aolibc for 64-bit
RUN cd /opt/aolibc && make CC="emcc -s WASM=1 -s MEMORY64=1 -s SUPPORT_LONGJMP=1"

ENV CC='emcc -s WASM=1'
Expand Down
19 changes: 13 additions & 6 deletions dev-cli/container/src/ao-build-module
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def main():
'-g2',
# '-s', 'MAIN_MODULE', # This is required to load dynamic libraries at runtime
'-s', 'ASYNCIFY=1',
'-s', 'MEMORY64=1',
'-s', 'STACK_SIZE=' + str(config.stack_size),
'-s', 'ASYNCIFY_STACK_SIZE=' + str(config.stack_size),
'-s', 'ALLOW_MEMORY_GROWTH=1',
Expand All @@ -116,9 +115,18 @@ def main():
'-msimd128',
'--pre-js', '/opt/pre.js'
]

# Link aolibc library
cmd.extend(['-L/opt/aolibc', '-l:aolibc.a'])

# If the target is 64 bit, add the MEMORY64 flag and link against 64 bit libraries
if config.target == 64:
cmd.extend(['-sMEMORY64=1'])
cmd.extend(['-L/opt/aolibc', '-l:aolibc.a'])
cmd.extend(['-I', quote('/lua-{}/src'.format(os.environ.get('LUA_VERSION')))])
cmd.extend([quote('/lua-{}/src/liblua.a'.format(os.environ.get('LUA_VERSION')))])
# If the target is 32 bit, link against 32 bit libraries
else:
cmd.extend(['-L/opt/aolibc', '-l:aolibc32.a'])
cmd.extend(['-I', quote('/lua-{}-32/src'.format(os.environ.get('LUA_VERSION')))])
cmd.extend([quote('/lua-{}-32/src/liblua.a'.format(os.environ.get('LUA_VERSION')))])

# Link Rust library
if(language == 'rust'):
Expand All @@ -128,14 +136,13 @@ def main():
cmd.extend(definition.get_extra_args())

# Add the lua include path
cmd.extend(['-I', quote('/lua-{}/src'.format(os.environ.get('LUA_VERSION')))])

# Add all c source files if there are any
for f in c_source_files:
cmd.append(quote(f))

# Add the compile file and link libraries
cmd.extend(['/tmp/compile.c', quote('/lua-{}/src/liblua.a'.format(os.environ.get('LUA_VERSION')))])
cmd.extend(['/tmp/compile.c'])
cmd.extend([quote(v.filepath) for v in link_libraries])
cmd.extend([quote(v.filepath) for v in dependency_libraries])
cmd.extend(config.get_extra_args())
Expand Down
15 changes: 15 additions & 0 deletions dev-cli/container/src/ao_module_lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Config():
maximum_memory = 0
extra_compile_args = []
keep_js = False
target = 64

def __init__(self, config_file):

Expand All @@ -69,6 +70,20 @@ def __init__(self, config_file):
self.maximum_memory = data.get('maximum_memory', self.maximum_memory)
self.extra_compile_args = data.get('extra_compile_args', self.extra_compile_args)
self.keep_js = data.get('keep_js', self.keep_js)
self.setTarget(data.get('target', self.target))


def setTarget(self, value):
if(not isinstance(value, int) and not isinstance(value, str)):
print('Invalid target. Defaulting to 64 bit')
value = 64
else:
if(isinstance(value, str)):
value = int(value)
if(value != 64 and value != 32):
print('Invalid target. Defaulting to 64 bit')
value = 64
self.target = value

def setValuesByPreset(self, preset):
self.preset = preset
Expand Down

0 comments on commit ab31154

Please sign in to comment.