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

emsdk_installer init #6163

Merged
merged 48 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
cc3cad4
init
werto87 Jul 5, 2021
4fbbf62
hook fixes
werto87 Jul 5, 2021
a864958
fixing changes on two recipe problem
werto87 Jul 7, 2021
e9fd817
removed readme
werto87 Jul 7, 2021
0a01d5e
wip cmake version
werto87 Jul 7, 2021
ad37503
try to fix build error adding test_type
werto87 Jul 10, 2021
4b013be
run build and test if os is Emscripten
werto87 Jul 11, 2021
da21729
removed verbose print cmake
werto87 Jul 11, 2021
c3a1d98
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
8b022c1
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
e3ef04e
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
a75f3ea
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
3843aaa
Update recipes/emsdk_installer/all/test_package/CMakeLists.txt
werto87 Jul 14, 2021
05b5ccf
Update recipes/emsdk_installer/all/test_package/conanfile.py
werto87 Jul 14, 2021
6737ff8
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
233341f
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
9b06f4e
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
828c57b
Update recipes/emsdk_installer/all/conanfile.py
werto87 Jul 14, 2021
1676d2e
rename emsdk_installer into emsdk
werto87 Jul 14, 2021
2f34c8c
fixed missing else
werto87 Jul 14, 2021
e86380a
progpergate renaming
werto87 Jul 14, 2021
3fbda29
remove _run print
werto87 Jul 14, 2021
5b23572
removed not used import
werto87 Jul 14, 2021
bfffb8d
emsdk: bump to 2.0.26 + always run test package
madebr Aug 13, 2021
19e700d
remove package id
werto87 Aug 13, 2021
83ace2e
do not copy forbiden files
werto87 Aug 14, 2021
da29974
only coppy allowed files
werto87 Aug 14, 2021
0c87f09
added arch as setting
werto87 Aug 14, 2021
d8b7272
only allow arch wasm
werto87 Aug 14, 2021
ef7fbef
build target arch should be wasm or asm.js
werto87 Aug 14, 2021
d04ab65
mark m1 as invalid config
werto87 Aug 14, 2021
e97c334
trying to disable m1
werto87 Aug 14, 2021
1dfd5a4
trying to fix m1
werto87 Aug 14, 2021
a619334
m1
werto87 Aug 14, 2021
556aafc
install should be in package and not in build
werto87 Aug 29, 2021
e50e557
Merge remote-tracking branch 'madebr/pr6163' into werto87-emsdk
jgsogo Sep 25, 2021
b3e5e8b
use NodeJS from conan package
jgsogo Sep 25, 2021
34d4e37
Merge pull request #2 from jgsogo/werto87-emsdk
werto87 Sep 26, 2021
06d950c
Update recipes/emsdk/config.yml
werto87 Sep 26, 2021
158bc46
Update recipes/emsdk/all/conanfile.py
werto87 Sep 27, 2021
81474a7
please rerun ci
werto87 Sep 30, 2021
ef3b636
Update recipes/emsdk/all/test_package/conanfile.py
SSE4 Oct 2, 2021
c02b57a
Update recipes/emsdk/all/test_package/conanfile.py
SSE4 Oct 2, 2021
c7d5953
Update recipes/emsdk/all/test_package/conanfile.py
SSE4 Oct 2, 2021
0ce1ece
Update recipes/emsdk/all/conanfile.py
SSE4 Oct 2, 2021
cd00ec4
fix crosscompiling scenarios
jgsogo Oct 4, 2021
9f4e9f0
check settings_target before using it
jgsogo Oct 4, 2021
487e64d
settings_target can be None
jgsogo Oct 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/emsdk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.0.30":
url: https://github.com/emscripten-core/emsdk/archive/refs/tags/2.0.30.tar.gz
sha256: 69050d76c8907a58f99b08831e8cb7a4fba857efec6037d5e59df4b73111ba36
140 changes: 140 additions & 0 deletions recipes/emsdk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os
import json

required_conan_version = ">=1.33.0"


class EmSDKConan(ConanFile):
name = "emsdk"
description = "Emscripten SDK. Emscripten is an Open Source LLVM to JavaScript compiler"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/kripken/emscripten"
topics = ("emsdk", "emscripten", "sdk")
license = "MIT"
settings = "os", "arch"

short_paths = True

@property
def _source_subfolder(self):
return "source_subfolder"

def requirements(self):
self.requires("nodejs/16.3.0")
# self.requires("python") # FIXME: Not available as Conan package
# self.requires("wasm") # FIXME: Not available as Conan package

def validate(self):
if hasattr(self, "settings_target") and self.settings_target:
if self.settings_target.os != "Emscripten":
raise ConanInvalidConfiguration("When using {}, target os must be Emscripten".format(self.name))

def package_id(self):
del self.info.settings.os
werto87 marked this conversation as resolved.
Show resolved Hide resolved
SSE4 marked this conversation as resolved.
Show resolved Hide resolved

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)

@staticmethod
def _chmod_plus_x(filename):
if os.name == "posix":
os.chmod(filename, os.stat(filename).st_mode | 0o111)

def _tools_for_version(self):
ret = {}
# Select release-upstream from version (wasm-binaries)
with open(os.path.join(self.build_folder, self._source_subfolder, "emscripten-releases-tags.json"), 'r') as f:
data = json.load(f)
ret['wasm'] = "releases-upstream-{}-64bit".format(data["releases"][self.version])
# Select python and node versions
with open(os.path.join(self.build_folder, self._source_subfolder, "emsdk_manifest.json"), 'r') as f:
data = json.load(f)
tools = data["tools"]
if self.settings.os != "Linux":
python = next((it for it in tools if (it["id"] == "python" and not it.get("is_old", False))), None)
ret["python"] = "python-{}-64bit".format(python["version"])
node = next((it for it in tools if (it["id"] == "node" and not it.get("is_old", False))), None)
ret["nodejs"] = "node-{}-64bit".format(node["version"])
return ret

def build(self):
with tools.chdir(self._source_subfolder):
emsdk = "emsdk.bat" if tools.os_info.is_windows else "./emsdk"
self._chmod_plus_x("emsdk")

# Install required tools
required_tools = self._tools_for_version()
for key, value in required_tools.items():
if key != 'nodejs':
self.run("%s install %s" % (emsdk, value))
self.run("%s activate %s" % (emsdk, value))

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*", dst="bin", src=self._source_subfolder)
emscripten = os.path.join(self.package_folder, "bin", "upstream", "emscripten")
toolchain = os.path.join(emscripten, "cmake", "Modules", "Platform", "Emscripten.cmake")
# FIXME: conan should add the root of conan package requirements to CMAKE_PREFIX_PATH (LIBRARY/INCLUDE -> ONLY; PROGRAM -> NEVER)
# allow to find conan libraries
tools.replace_in_file(toolchain,
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)",
"set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)")
tools.replace_in_file(toolchain,
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)",
"set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)")
tools.replace_in_file(toolchain,
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)",
"set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)")

def _define_tool_var(self, name, value):
suffix = ".bat" if self.settings.os == "Windows" else ""
path = os.path.join(self.package_folder, "bin", "upstream",
"emscripten", "%s%s" % (value, suffix))
self._chmod_plus_x(path)
self.output.info("Creating %s environment variable: %s" % (name, path))
return path

def package_info(self):
emsdk = self.package_folder
em_config = os.path.join(emsdk, "bin", ".emscripten")
emscripten = os.path.join(emsdk, "bin", "upstream", "emscripten")
em_cache = os.path.join(emsdk, "bin", ".emscripten_cache")
toolchain = os.path.join(emscripten, "cmake", "Modules", "Platform", "Emscripten.cmake")

self.output.info("Appending PATH environment variable: %s" % emsdk)
self.env_info.PATH.append(emsdk)

self.output.info("Appending PATH environment variable: %s" % emscripten)
self.env_info.PATH.append(emscripten)

self.output.info("Creating EMSDK environment variable: %s" % emsdk)
self.env_info.EMSDK = emsdk

self.output.info("Creating EMSCRIPTEN environment variable: %s" % emscripten)
self.env_info.EMSCRIPTEN = emscripten

self.output.info("Creating EM_CONFIG environment variable: %s" % em_config)
self.env_info.EM_CONFIG = em_config

self.output.info("Creating EM_CACHE environment variable: %s" % em_cache)
self.env_info.EM_CACHE = em_cache

self.output.info("Creating CONAN_CMAKE_TOOLCHAIN_FILE environment variable: %s" % toolchain)
self.env_info.CONAN_CMAKE_TOOLCHAIN_FILE = toolchain

self.env_info.CC = self._define_tool_var("CC", "emcc")
self.env_info.CXX = self._define_tool_var("CXX", "em++")
self.env_info.RANLIB = self._define_tool_var("RANLIB", "emranlib")
self.env_info.AR = self._define_tool_var("AR", "emar")
self.cpp_info.builddirs = [
"bin/releases/src",
"bin/upstream/emscripten/cmake/Modules",
"bin/upstream/emscripten/cmake/Modules/Platform",
"bin/upstream/emscripten/system/lib/libunwind/cmake/Modules",
"bin/upstream/emscripten/system/lib/libunwind/cmake",
"bin/upstream/emscripten/tests/cmake/target_library",
"bin/upstream/lib/cmake/llvm",
]
14 changes: 14 additions & 0 deletions recipes/emsdk/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.18.2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In ConanCenter we will converge to the minimum requirements for Conan v2, to maximize compatibility of recipes with the next Conan versions. Requirement for Conan v2 is CMake 3.15 (https://github.com/conan-io/tribe/blob/main/design/004-tools-cmake.md), so we try to ensure our recipes works with it.

Here I don't see anything requiring that CMake version, so it is probably safe to use something lower

project(test_package)

option(USE_CONANBUILDINFO "Use conanbuildinfo.cmake")

if(USE_CONANBUILDINFO)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin)
endif()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
37 changes: 37 additions & 0 deletions recipes/emsdk/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from conans import ConanFile, CMake, tools
import os

required_conan_version = ">=1.36.0"


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
test_type = "build_requires"
werto87 marked this conversation as resolved.
Show resolved Hide resolved
generators = "cmake"

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def build_requirements(self):
self.build_requires("cmake/3.18.2")
if self._settings_build.os == "Windows":
SSE4 marked this conversation as resolved.
Show resolved Hide resolved
self.build_requires("make/4.3")

def build(self):
SSE4 marked this conversation as resolved.
Show resolved Hide resolved
SSE4 marked this conversation as resolved.
Show resolved Hide resolved
clang = os.path.join(self.deps_cpp_info["emsdk"].rootpath, "bin", "upstream", "bin", "clang")
if self.settings.os == "Macos":
self.run("file %s" % clang)
self.run("otool -falh %s" % clang)
self.run("emcc -v", run_environment=True)
self.run("em++ -v", run_environment=True)
cmake = CMake(self, generator="Unix Makefiles")
cmake.definitions["USE_CONANBUILDINFO"] = self.settings.os == "Emscripten"
cmake.configure()
cmake.build()

def test(self):
test_file = os.path.join("bin", "test_package.js")
assert os.path.isfile(test_file)
if tools.which("node"):
self.run("node %s" % test_file, run_environment=True)
8 changes: 8 additions & 0 deletions recipes/emsdk/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <cstdlib>
#include <iostream>

int main()
{
std::cout << "conan-center-index\n";
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/emsdk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.0.30":
folder: all