Skip to content

object file is not write on the mounted directory. #467

@liudonghua123

Description

@liudonghua123

Hi, I tried to use clang wasm to compile the c source code.

I can use cli command: wasmer run clang --mapdir /sysroot:./sysroot32 --mapdir /lib:./lib-small --dir . -- -cc1 -triple wasm32-unknown-wasi -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -ffp-exception-behavior=ignore -mconstructor-aliases -target-feature +atomics -target-feature +bulk-memory -target-feature +mutable-globals -target-feature +sign-ext -target-cpu generic -target-feature +atomics -target-feature +bulk-memory -target-feature +mutable-globals -fvisibility=hidden -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home -resource-dir /lib/clang/16 -D _WASI_EMULATED_MMAN -D _WASI_EMULATED_SIGNAL -D _WASI_EMULATED_PROCESS_CLOCKS -D USE_TIMEGM -isysroot /sysroot -internal-isystem /lib/clang/16/include -internal-isystem /sysroot/include/wasm32-wasi -internal-isystem /sysroot/include -fdebug-compilation-dir=/home -ferror-limit 19 -ftls-model=local-exec -pthread -fgnuc-version=4.2.1 -o test.o -x c test.c to generate the object file, but if I use @wasmer/sdk, the command executed ok with exitCode 0, stdout "", stderr "". But inspect the object file. it's not exists.

The related js code:

        // 2. Run Clang
        // clang ... -o test.o -x c test.c
        term.write("Running clang...\r\n");
        const clangPkg = await Wasmer.fromFile(pkg.clang);
        const clangInstance = await clangPkg.entrypoint.run({
            args: [
                "-cc1", "-triple", "wasm32-unknown-wasi", "-emit-obj", "-disable-free",
                "-isysroot", "/sysroot",
                "-internal-isystem", "/lib/clang/16/include",
                "-internal-isystem", "/sysroot/include/wasm32-wasi",
                "-internal-isystem", "/sysroot/include",
                "-ferror-limit", "19", 
                "-o", "/test.o", "-x", "c", "/test.c"
            ],
            mount: {
                "/": rootDir,
                "/sysroot": sysrootDir,
                "/lib": libDir
            },
            cwd: '/',
        });
        
        const clangResult = await clangInstance.wait();
        if (clangResult.stdout) term.write(clangResult.stdout);
        if (clangResult.stderr) term.write(clangResult.stderr);
        
        if (clangResult.code !== 0) {
             throw new Error(`clang failed with code ${clangResult.code}`);
        }
        term.write("clang done.\r\n");
        try {
            const objFile = await rootDir.readFile("/test.o");
            console.log("Found test.o, size:", objFile.length);
        } catch (e) {
            console.error("test.o still not found in rootDir");
        }
        const res1 = await rootDir.readDir("/");
        console.info(res1)
        
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions