Skip to content

Commit

Permalink
es6 build
Browse files Browse the repository at this point in the history
es6 for emscripten build
initial memory increase for wasi
  • Loading branch information
petersalomonsen committed Dec 22, 2023
1 parent 844fa31 commit 65727f7
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion emscriptenbuild/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ fi
# Before building, remove any ../libgit2/src/ transports/emscriptenhttp.c left from running setup.sh
[ -f "../libgit2/src/libgit2/transports/emscriptenhttp-async.c" ] && rm ../libgit2/src/libgit2/transports/emscriptenhttp-async.c

emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS --pre-js $(pwd)/pre.js $POST_JS -s \"EXTRA_EXPORTED_RUNTIME_METHODS=['FS','callMain']\" -sFORCE_FILESYSTEM -sWASMFS -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=131072" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2
emcmake cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS --pre-js $(pwd)/pre.js $POST_JS -s \"EXTRA_EXPORTED_RUNTIME_METHODS=['FS','callMain']\" -sFORCE_FILESYSTEM -sEXPORT_ES6 -sWASMFS -s INVOKE_RUN=0 -s ALLOW_MEMORY_GROWTH=1 -s STACK_SIZE=131072" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DTHREADSAFE=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2
emmake make lg2
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "wasm-git",
"version": "0.0.11",
"type": "module",
"author": {
"name": "Peter Salomonsen",
"url": "https://petersalomonsen.com"
Expand Down
4 changes: 2 additions & 2 deletions test/checkout.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const lgPromise = require('./common.js').lgPromise;
const assert = require('assert');
import { lgPromise } from './common.js';
import assert from 'assert';

describe('git checkout', () => {
beforeEach(async () => {
Expand Down
11 changes: 1 addition & 10 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
module.exports = {
lgPromise: new Promise(resolve => {
const lg = require('./lg2.js');
lg.onRuntimeInitialized = () => {
const FS = lg.FS;

resolve(lg);
};
})
}
export const lgPromise = await import('./lg2.js').then(r => r.default());
4 changes: 2 additions & 2 deletions test/conflict.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const lgPromise = require('./common.js').lgPromise;
const assert = require('assert');
import { lgPromise } from './common.js';
import assert from 'assert';

describe('conflicts', function() {
beforeEach(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/fetch.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert');
const lgPromise = require('./common.js').lgPromise;
import { lgPromise } from './common.js';
import assert from 'assert';

describe('git fetch', () => {
beforeEach(async () => {
Expand Down
4 changes: 1 addition & 3 deletions test/hellowasmfs.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const lgPromise = require('./common.js').lgPromise;
const assert = require('assert');
import { lgPromise } from './common.js';

describe.only('hello wasmfs', () => {
it.only('hello wasmfs', async () => {
const lg = await lgPromise;
const FS = lg.FS;


FS.mkdir('/test');
FS.chdir('/test');
lg.callMain(['init', '.']);
Expand Down
6 changes: 3 additions & 3 deletions test/nodefs.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const lgPromise = require('./common.js').lgPromise;
const assert = require('assert');
const { rmSync } = require('fs');
import { lgPromise } from './common.js';
import assert from 'assert';
import {rmSync} from 'fs';

describe('nodefs', function () {
this.timeout(20000);
Expand Down
4 changes: 2 additions & 2 deletions test/revert.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const lgPromise = require('./common.js').lgPromise;
const assert = require('assert');
import { lgPromise } from './common.js';
import assert from 'assert';

describe('git revert', () => {
beforeEach(async () => {
Expand Down
2 changes: 1 addition & 1 deletion wasibuild/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ clang --target=wasm32-wasi --sysroot=wasi-sdk-20.0/share/wasi-sysroot -D_WASI_EM
clang --target=wasm32-wasi --sysroot=wasi-sdk-20.0/share/wasi-sysroot -D_WASI_EMULATED_MMAN -Iwasi_mocks -c wasi_mocks/posix_mocks.c -o wasi_mocks/posix_mocks.o
cmake -DCMAKE_TOOLCHAIN_FILE=`pwd`/wasi_toolchain.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_FLAGS="$EXTRA_CMAKE_C_FLAGS" -DREGEX_BACKEND=regcomp -DSONAME=OFF -DUSE_HTTPS=OFF -DBUILD_SHARED_LIBS=OFF -DUSE_THREADS=OFF -DUSE_SSH=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=ON ../libgit2
make lg2 VERBOSE=1

mv examples/lg2 lg2.wasm
10 changes: 5 additions & 5 deletions wasibuild/wasi_mocks/posix_mocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pid_t getsid(pid_t pid) {
}

uid_t getuid(void) {
return 1000; // Mock UID
return 0; // Mock UID
}

gid_t getgid(void) {
Expand All @@ -38,7 +38,7 @@ int chmod(const char *pathname, mode_t mode) {
}

uid_t geteuid(void) {
return 1000; // Mock effective UID
return 0; // Mock effective UID
}

struct passwd *getpwuid(uid_t uid) {
Expand Down Expand Up @@ -66,12 +66,12 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct p
}

// You can fill in the `pwd` structure with mock data as needed
pwd->pw_name = "mockuser";
pwd->pw_name = "codespace";
pwd->pw_passwd = "mockpassword";
pwd->pw_uid = uid;
pwd->pw_gid = 1000; // Mock GID
pwd->pw_gid = 0; // Mock GID
pwd->pw_gecos = "Mock User";
pwd->pw_dir = "/home/mockuser";
pwd->pw_dir = "/home/codespace";
pwd->pw_shell = "/bin/sh";

// Copy the structure to the provided buffer
Expand Down
8 changes: 4 additions & 4 deletions wasibuild/wasi_mocks/pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ struct passwd *getpwnam(const char *name) {
static struct passwd mock_user;

// Hardcoded user information
mock_user.pw_name = "mockuser";
mock_user.pw_name = "codespace";
mock_user.pw_passwd = "mockpassword";
mock_user.pw_uid = 1000;
mock_user.pw_gid = 1000;
mock_user.pw_uid = 0;
mock_user.pw_gid = 0;
mock_user.pw_gecos = "Mock User";
mock_user.pw_dir = "/home/mockuser";
mock_user.pw_dir = "/home/codespace";
mock_user.pw_shell = "/bin/sh";

return &mock_user;
Expand Down
2 changes: 1 addition & 1 deletion wasibuild/wasi_toolchain.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SET(CMAKE_C_COMPILER clang)
SET(CMAKE_FIND_ROOT_PATH ${CMAKE_CURRENT_LIST_DIR}/wasi-sdk-20.0/share/wasi-sysroot/)
SET(CMAKE_SYSROOT ${CMAKE_CURRENT_LIST_DIR}/wasi-sdk-20.0/share/wasi-sysroot/)
set(CMAKE_C_FLAGS "--target=wasm32-wasi -I${CMAKE_CURRENT_LIST_DIR}/wasi_mocks -D_WASI_EMULATED_MMAN ${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "--target=wasm32-wasi -Wl,--initial-memory=268435456 -I${CMAKE_CURRENT_LIST_DIR}/wasi_mocks -D_WASI_EMULATED_MMAN ${CMAKE_C_FLAGS}")

set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${CMAKE_SYSROOT}/include")

Expand Down

0 comments on commit 65727f7

Please sign in to comment.