Skip to content

Several failures with wasm targets and cc/c++ toolchains (and problems with lto) #22629

@KaruroChori

Description

@KaruroChori

Zig Version

0.14.0-dev.2851+b074fb7dd

Steps to Reproduce and Observed Behavior

Very simple c++ file:

#include <iostream>

int main(){
	std::cout<<"hello\n";
	return 0;
}

And a c one:

#include <stdio.h>

int main(){
	printf("hello\n");
	return 0;
}

Running the following commands, result on the right:

zig c++ --target=wasm32-wasi main.cpp -flto -> fail to run
zig c++ --target=wasm32-wasi main.cpp -> fail, surprisingly as from meson it works.
zig cc --target=wasm32-wasi main.c -flto -> fail to run
zig cc --target=wasm32-wasi main.c -> working

I also tested the C++ cases using the C code, so no libc++ and it works without -flto.
For failure, I mean that running it via a wasm/wasi runtime like bun, it results in an exception from the runtime.

I also noticed that the -static attribute does not work, so zig cc main.c -static does not generate a static build, but clang would.

Expected Behavior

All the previous cases should just compile and run fine.
So, running bun run a.out should just display hello for each of the test cases.
Further problems and discussion @ lazy-eggplant/vs.templ#18 where some of these issues were first isolated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions