Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes tracking #5317

Closed
wants to merge 13 commits into from
15 changes: 13 additions & 2 deletions lib/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ fn main() {
let _ = std::fs::remove_dir_all(&wamr_dir);
std::fs::rename(zip_dir, &wamr_dir).expect("failed to rename wamr dir");

let wamr_platform_dir = wamr_dir.join("product-mini/platforms").join(target_os);
let wamr_platform_dir = match target_os {
"ios" => PathBuf::from(&crate_root).join("third_party/wamr_ios"),
_ => wamr_dir.join("product-mini/platforms").join(target_os),
};
let mut dst = Config::new(wamr_platform_dir.as_path());

dst.always_configure(true)
Expand Down Expand Up @@ -85,6 +88,14 @@ fn main() {
.define("WAMR_DISABLE_HW_BOUND_CHECK", "1")
.define("WAMR_BUILD_TARGET", target_arch);

if target_os == "ios" {
match env::var("PLATFORM_NAME").expect("PLATFORM_NAME").as_str() {
"iphonesimulator" => dst.define("CMAKE_OSX_SYSROOT", "iphonesimulator"),
"iphoneos" => dst.define("CMAKE_OSX_SYSROOT", "iphoneos"),
_ => unimplemented!(),
};
}

if target_os == "windows" {
dst.define("CMAKE_CXX_COMPILER", "cl.exe");
dst.define("CMAKE_C_COMPILER", "cl.exe");
Expand Down Expand Up @@ -123,7 +134,7 @@ fn main() {
"cargo:rustc-link-search=native={}",
dst.join("build").display()
);
println!("cargo:rustc-link-lib=vmlib");
println!("cargo:rustc-link-lib=static=vmlib");

let bindings = bindgen::Builder::default()
.header(
Expand Down
148 changes: 148 additions & 0 deletions lib/api/third_party/wamr_ios/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required (VERSION 3.21)


project (iwasm)

set (WAMR_BUILD_PLATFORM "darwin")
set (WAMR_BUILD_TYPE Release)
set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)
set (WAMR_BUILD_LIBC_WASI 1)

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
endif ()

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif ()

set(CMAKE_CXX_STANDARD 17)

if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
# Enable AOT by default.
set (WAMR_BUILD_AOT 1)
endif ()

if (NOT DEFINED WAMR_BUILD_JIT)
# Disable JIT by default.
set (WAMR_BUILD_JIT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_FAST_JIT)
# Disable Fast JIT by default
set (WAMR_BUILD_FAST_JIT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
# Enable libc builtin support by default
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif ()

if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
# Enable libc wasi support by default
set (WAMR_BUILD_LIBC_WASI 1)
endif ()

if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
# Enable fast interpreter
set (WAMR_BUILD_FAST_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_MULTI_MODULE)
# Disable multiple module by default
set (WAMR_BUILD_MULTI_MODULE 0)
endif ()

if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
# Disable pthread library by default
set (WAMR_BUILD_LIB_PTHREAD 1)
endif ()

if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
# Disable wasm mini loader by default
set (WAMR_BUILD_MINI_LOADER 0)
endif ()

if (NOT DEFINED WAMR_BUILD_SIMD)
# Enable SIMD by default
set (WAMR_BUILD_SIMD 1)
endif ()

if (NOT DEFINED WAMR_BUILD_DEBUG_INTERP)
# Disable Debug feature by default
set (WAMR_BUILD_DEBUG_INTERP 0)
endif ()

if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
set (WAMR_BUILD_FAST_INTERP 0)
set (WAMR_BUILD_MINI_LOADER 0)
set (WAMR_BUILD_SIMD 0)
endif ()

set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../wamr)

set (WAMR_BUILD_LIB_WASI_THREADS 1)

include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE")

set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")

if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
endif ()
endif ()

# The following flags are to enhance security, but it may impact performance,
# we disable them by default.
#if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftrapv -D_FORTIFY_SOURCE=2")
#endif ()
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong --param ssp-buffer-size=4")
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")

add_library (vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE})
if (CMAKE_BUILD_TYPE STREQUAL Release)
target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -s)
else()
target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl)
endif()

set (distribution_DIR ${CMAKE_BINARY_DIR}/distribution)
set_target_properties (vmlib PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${distribution_DIR}/wasm/lib")

add_custom_command (TARGET vmlib POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_directory "${WAMR_ROOT_DIR}/core/iwasm/include" "${distribution_DIR}/wasm/include/"
COMMENT "Copying iwasm to output directory")
13 changes: 1 addition & 12 deletions lib/cli/src/commands/gen_c_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,7 @@ impl GenCHeader {
None => crate::commands::PrefixMapCompilation::hash_for_bytes(&file),
};

let atom = match from_bytes(file.clone()) {
Ok(webc) => self.get_atom(&webc)?,
Err(WasmerPackageError::ContainerError(ContainerError::Detect(
DetectError::InvalidMagic { .. },
))) => {
// we've probably got a WebAssembly file
file.into()
}
Err(other) => {
return Err(Error::new(other).context("Unable to parse the webc file"));
}
};
let atom: SharedBytes = file.into();

let target_triple = self.target_triple.clone().unwrap_or_else(Triple::host);
let target = crate::commands::create_exe::utils::target_triple_to_target(
Expand Down
4 changes: 4 additions & 0 deletions lib/compiler-llvm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl SymbolRegistry for ShortNames {
fn symbol_to_name(&self, symbol: Symbol) -> String {
match symbol {
Symbol::Metadata => "M".to_string(),
Symbol::MetadataSize => "S".to_string(),
Symbol::LocalFunction(index) => format!("f{}", index.index()),
Symbol::Section(index) => format!("s{}", index.index()),
Symbol::FunctionCallTrampoline(index) => format!("t{}", index.index()),
Expand All @@ -65,6 +66,9 @@ impl SymbolRegistry for ShortNames {
if ty.starts_with('M') {
return Some(Symbol::Metadata);
}
if ty.starts_with('S') {
return Some(Symbol::MetadataSize);
}

let idx = idx.parse::<u32>().ok()?;
match ty.chars().next().unwrap() {
Expand Down
17 changes: 11 additions & 6 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,15 +1026,20 @@ impl Artifact {
}
.symbol_to_name(crate::types::symbols::Symbol::Metadata);

emit_data(&mut obj, object_name.as_bytes(), &metadata_binary, 1)
.map_err(to_compile_error)?;

emit_compilation(&mut obj, compilation, &symbol_registry, target_triple)
.map_err(to_compile_error)?;
let metadata_binary_len = metadata_binary.len();

emit_compilation(
&mut obj,
compilation,
&symbol_registry,
metadata_binary,
target_triple,
)
.map_err(to_compile_error)?;
Ok((
Arc::try_unwrap(metadata.compile_info.module).unwrap(),
obj,
metadata_binary.len(),
metadata_binary_len,
Box::new(symbol_registry),
))
}
Expand Down
Loading
Loading