Skip to content

wasm32-unknown-emscripten target shouldn't use -fno-exceptions #1680

Description

@sssxks

Background

#1284 introduced f no exceptions for all wasm targets

rust-or/highs-sys#43 encountered this issue on wasm32-unknown-emscripten

Repro

use std::env;

fn main() {
    println!("cargo:rerun-if-changed=native/throw.cpp");
    println!("cargo:rerun-if-env-changed=REPRO_FIX");

    let target = env::var("TARGET").expect("TARGET not set by cargo");
    let mut build = cc::Build::new();
    build.cpp(true).file("native/throw.cpp");

    if env::var_os("REPRO_FIX").is_some() {
        build.no_default_flags(true);
        if target.contains("emscripten") {
            build.flag("-fexceptions");
        }
    }

    build.compile("throwlib");
}

native/throw.cpp

int throw_and_catch() {
  try {
    throw 42;
  } catch (...) {
    return 0;
  }
}

pin cc = "=1.2.56", output contains

warning: emrepro@0.1.0: native/throw.cpp:3:5: error: cannot use 'throw' with exceptions disabled
warning: emrepro@0.1.0:     3 |     throw 42;
warning: emrepro@0.1.0:       |     ^
warning: emrepro@0.1.0: native/throw.cpp:2:3: error: cannot use 'try' with exceptions disabled
warning: emrepro@0.1.0:     2 |   try {
warning: emrepro@0.1.0:       |   ^
warning: emrepro@0.1.0: 2 errors generated.
error: failed to run custom build command for `emrepro v0.1.0 (/home/xks/repos/highs-sys/repro/cc-rs-emscripten-exceptions)`

Caused by:
  process didn't exit successfully: `/home/xks/repos/highs-sys/repro/cc-rs-emscripten-exceptions/target/debug/build/emrepro-c20309397f2411a0/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-changed=native/throw.cpp
  cargo:rerun-if-env-changed=REPRO_FIX
  OUT_DIR = Some(/home/xks/repos/highs-sys/repro/cc-rs-emscripten-exceptions/target/wasm32-unknown-emscripten/debug/build/emrepro-a032e2f52b0f0067/out)
  OPT_LEVEL = Some(0)
  TARGET = Some(wasm32-unknown-emscripten)
  CARGO_ENCODED_RUSTFLAGS = Some()
  HOST = Some(x86_64-unknown-linux-gnu)
  cargo:rerun-if-env-changed=CXX_wasm32-unknown-emscripten
  CXX_wasm32-unknown-emscripten = None
  cargo:rerun-if-env-changed=CXX_wasm32_unknown_emscripten
  CXX_wasm32_unknown_emscripten = None
  cargo:rerun-if-env-changed=TARGET_CXX
  TARGET_CXX = None
  cargo:rerun-if-env-changed=CXX
  CXX = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(true)
  cargo:rerun-if-env-changed=CXXFLAGS
  CXXFLAGS = None
  cargo:rerun-if-env-changed=TARGET_CXXFLAGS
  TARGET_CXXFLAGS = None
  cargo:rerun-if-env-changed=CXXFLAGS_wasm32_unknown_emscripten
  CXXFLAGS_wasm32_unknown_emscripten = None
  cargo:rerun-if-env-changed=CXXFLAGS_wasm32-unknown-emscripten
  CXXFLAGS_wasm32-unknown-emscripten = None
  cargo:warning=native/throw.cpp:3:5: error: cannot use 'throw' with exceptions disabled
  cargo:warning=    3 |     throw 42;
  cargo:warning=      |     ^
  cargo:warning=native/throw.cpp:2:3: error: cannot use 'try' with exceptions disabled
  cargo:warning=    2 |   try {
  cargo:warning=      |   ^
  cargo:warning=2 errors generated.

  --- stderr


  error occurred in cc-rs: command did not execute successfully (status code exit status: 1): LC_ALL="C" "em++" "-O0" "-ffunction-sections" "-fdata-sections" "-fno-exceptions" "-g" "-fno-omit-frame-pointer" "--target=wasm32-unknown-emscripten" "-Wall" "-Wextra" "-o" "/home/xks/repos/highs-sys/repro/cc-rs-emscripten-exceptions/target/wasm32-unknown-emscripten/debug/build/emrepro-a032e2f52b0f0067/out/44f7d3c4c0a9780b-throw.o" "-c" "native/throw.cpp"

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