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

Make emsdk a proper Python package #1043

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- run:
name: test.py
command: |
source emsdk_env.sh
source emsdkpy/emsdk_env.sh
Copy link
Member

Choose a reason for hiding this comment

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

In general I think this sounds good - having a proper python package could be useful in various ways!

I am concerned by breaking changes, though, like moving scripts out of the toplevel where users have expected them for long time. Is there a way to avoid such breaking changes? Perhaps we could create a new repo just for the package, which would include the main emsdk repo underneath it? Or maybe symlinks could help?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your response. Indeed I've thought about not moving the scripts around at first, but I've not been able to do that. IIRC the issue was for installing the scripts as package_data for the Python package, which was not possible if not under a Python module. But I can give another try.

test/test.py
test-mac:
macos:
Expand All @@ -64,7 +64,7 @@ jobs:
- run:
name: test.py
command: |
source emsdk_env.sh
source emsdkpy/emsdk_env.sh
test/test.py
test-windows:
executor:
Expand All @@ -90,7 +90,7 @@ jobs:
- run:
name: test.py
command: |
source emsdk_env.sh
source emsdkpy/emsdk_env.sh
python test/test.py

- run:
Expand Down
45 changes: 24 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*.pyc
__pycache__
emsdk.egg-info
dist
build

# Support for --embedded configs
/.emscripten
Expand All @@ -10,26 +13,26 @@ __pycache__
/.emscripten_sanity_wasm

# Tags files that get generated at runtime
/emscripten-releases-tot.txt
emsdkpy/emscripten-releases-tot.txt

# File that get download/extracted by emsdk itself
/ccache
/gnu
/upstream
/fastcomp
/fastcomp-clang/
/llvm
/ninja
/releases
/clang
/emscripten
/git
/node
/python
/temp
/zips
/crunch
/java
/mingw
/spidermonkey
/binaryen
emsdkpy/ccache
emsdkpy/gnu
emsdkpy/upstream
emsdkpy/fastcomp
emsdkpy/fastcomp-clang/
emsdkpy/llvm
emsdkpy/ninja
emsdkpy/releases
emsdkpy/clang
emsdkpy/emscripten
emsdkpy/git
emsdkpy/node
emsdkpy/python
emsdkpy/temp
emsdkpy/zips
emsdkpy/crunch
emsdkpy/java
emsdkpy/mingw
emsdkpy/spidermonkey
emsdkpy/binaryen
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include emsdk
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ That explains how to use the emsdk to get the latest binary builds (without
compiling from source). Basically, that amounts to

```
./emsdk install latest
./emsdk activate latest
emsdkpy/emsdk install latest
emsdkpy/emsdk activate latest
```

## SDK Concepts
Expand Down Expand Up @@ -100,8 +100,8 @@ available tools, run `emsdk list`.
* If a tool/SDK is currently active, a star * will be shown next to it.
* If a tool/SDK is currently active, but the terminal your are calling emsdk
from does not have `PATH` and environment set up to utilize that tool, a star
in parentheses (\*) will be shown next to it. Run `emsdk_env.bat` (Windows) or
`source ./emsdk_env.sh` (Linux and OS X) to set up the environment for the
in parentheses (\*) will be shown next to it. Run `emsdkpy/emsdk_env.bat` (Windows) or
`source emsdkpy/emsdk_env.sh` (Linux and OS X) to set up the environment for the
calling terminal.

### How do I install a tool/SDK version?
Expand Down
6 changes: 3 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ COPY . ${EMSDK}

RUN echo "## Install Emscripten" \
&& cd ${EMSDK} \
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
&& emsdkpy/emsdk install ${EMSCRIPTEN_VERSION} \
&& echo "## Done"

# This generates configuration that contains all valid paths according to installed SDK
# TODO(sbc): We should be able to use just emcc -v here but it doesn't
# currently create the sanity file.
RUN cd ${EMSDK} \
&& echo "## Generate standard configuration" \
&& ./emsdk activate ${EMSCRIPTEN_VERSION} \
&& emsdkpy/emsdk activate ${EMSCRIPTEN_VERSION} \
&& chmod 777 ${EMSDK}/upstream/emscripten \
&& chmod -R 777 ${EMSDK}/upstream/emscripten/cache \
&& echo "int main() { return 0; }" > hello.c \
Expand All @@ -41,7 +41,7 @@ RUN cd ${EMSDK} \

# Cleanup Emscripten installation and strip some symbols
RUN echo "## Aggressive optimization: Remove debug symbols" \
&& cd ${EMSDK} && . ./emsdk_env.sh \
&& cd ${EMSDK} && . emsdkpy/emsdk_env.sh \
# Remove debugging symbols from embedded node (extra 7MB)
&& strip -s `which node` \
# Tests consume ~80MB disc space
Expand Down
1 change: 1 addition & 0 deletions emsdkpy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .emsdk import main # noqa
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 7 additions & 5 deletions emsdk.py → emsdkpy/emsdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,7 +2554,7 @@ def set_active_tools(tools_to_activate, permanently_activate, system):

# Construct a .bat or .ps1 script that will be invoked to set env. vars and PATH
# We only do this on cmd or powershell since emsdk.bat/ps1 is able to modify the
# calling shell environment. On other shell `source emsdk_env.sh` is
# calling shell environment. On other shell `source emsdkpy/emsdk_env.sh` is
# required.
if CMD or POWERSHELL:
# always set local environment variables since permanently activating will only set the registry settings and
Expand Down Expand Up @@ -2833,7 +2833,9 @@ def expand_sdk_name(name, activating):
return name


def main(args):
def main():
args = sys.argv[1:]

if not args:
errlog("Missing command; Type 'emsdk help' to get a list of commands.")
return 1
Expand Down Expand Up @@ -3156,7 +3158,7 @@ def print_tools(t):

print('Items marked with * are activated for the current user.')
if has_partially_active_tools[0]:
env_cmd = 'emsdk_env.bat' if WINDOWS else 'source ./emsdk_env.sh'
env_cmd = 'emsdk_env.bat' if WINDOWS else 'source emsdkpy/emsdk_env.sh'
print('Items marked with (*) are selected for use, but your current shell environment is not configured to use them. Type "' + env_cmd + '" to set up your current shell to use them' + (', or call "emsdk activate --permanent <name_of_sdk>" to permanently activate them.' if WINDOWS else '.'))
if not arg_old:
print('')
Expand All @@ -3166,7 +3168,7 @@ def print_tools(t):
if is_emsdk_sourced_from_github():
print('Run "git pull" to pull in the latest list.')
else:
print('Run "./emsdk update" to pull in the latest list.')
print('Run "emsdkpy/emsdk update" to pull in the latest list.')

return 0
elif cmd == 'construct_env':
Expand Down Expand Up @@ -3268,4 +3270,4 @@ def print_tools(t):


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
sys.exit(main())
File renamed without changes.
4 changes: 2 additions & 2 deletions emsdk_env.csh → emsdkpy/emsdk_env.csh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# because it won't have any effect then.
# That is, always run this script with
#
# source ./emsdk_env.csh
# source emsdkpy/emsdk_env.csh
#
# instead of just plainly running with
#
# ./emsdk_env.csh
# emsdkpy/emsdk_env.csh
#
# which won't have any effect.
set SRC=($_)
Expand Down
2 changes: 1 addition & 1 deletion emsdk_env.fish → emsdkpy/emsdk_env.fish
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#In your Fish configuration, add this line:
#alias emsdk_setup ". /path/to/emsdk/emsdk_env.fish"
#alias emsdk_setup ". /path/to/emsdk/emsdkpy/emsdk_env.fish"
#Now, when you want to use the SDK, run this alias first to set up
#your environment.

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions emsdk_env.sh → emsdkpy/emsdk_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
# because it won't have any effect then.
# That is, always run this script with
#
# . /path/to/emsdk_env.sh
# . /path/to/emsdkpy/emsdk_env.sh
#
# or
#
# source /path/to/emsdk_env.sh
# source /path/to/emsdkpy/emsdk_env.sh
#
# instead of just plainly running with
#
# ./emsdk_env.sh
# emsdkpy/emsdk_env.sh
#
# which won't have any effect.

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion scripts/create_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main(args):
release_info['releases'] = OrderedDict(reversed(releases))
release_info['aliases']['latest'] = new_version

with open(os.path.join(root_dir, 'emscripten-releases-tags.json'), 'w') as f:
with open(os.path.join(root_dir, 'emsdkpy', 'emscripten-releases-tags.json'), 'w') as f:
f.write(json.dumps(release_info, indent=2))
f.write('\n')

Expand Down
6 changes: 3 additions & 3 deletions scripts/update_bazel_workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cd $(dirname $0)/..
# If the previous command succeeded. We are in the emsdk root. Check to make
# sure the files and directories we need are present.
if [[ $? = 0 ]]; then
if [[ ! -f emscripten-releases-tags.json ]]; then
if [[ ! -f emsdkpy/emscripten-releases-tags.json ]]; then
echo "Cannot find emscripten-releases-tags.json."
ERR=1
fi
Expand All @@ -38,7 +38,7 @@ URL2=/wasm-binaries

# Get commit hash for $1 version
get_hash () {
echo $(grep "$1" emscripten-releases-tags.json | grep -v latest | grep -v asserts | cut -f4 -d\")
echo $(grep "$1" emsdkpy/emscripten-releases-tags.json | grep -v latest | grep -v asserts | cut -f4 -d\")
}

# Get sha256 for $1 os $2 extname $3 hash $4 architecture
Expand All @@ -65,7 +65,7 @@ append_revision () {

# Get the latest version number from emscripten-releases-tag.json.
VER=$(grep -oP '(?<=latest\": \")([\d\.]+)(?=\")' \
emscripten-releases-tags.json \
emsdkpy/emscripten-releases-tags.json \
| sed --expression "s/\./\\\./g")

append_revision ${VER}
Expand Down
26 changes: 26 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[metadata]
name = emsdk
version = 3.1.9
description = Emscripten SDK
long_description = file: README.md
long_description_content_type = text/markdown
license_file = LICENSE
author = Emscripten authors
url = https://github.com/emscripten-core/emsdk
platforms = Windows, Linux, Mac OS X
keywords = emscripten, sdk

[bdist_wheel]
universal = 1

[options]
include_package_data = True
packages = find:
python_requires = >=3.7

[options.entry_points]
console_scripts =
emsdk = emsdkpy.emsdk:main

[options.package_data]
emsdkpy = emsdk, *.txt, *.bat, *.csh, *.fish, *.ps1, *.sh, *.json
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import setuptools

setuptools.setup()
6 changes: 3 additions & 3 deletions test/test.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
:: equivilent of test.sh as windows bat file
set PATH=%PATH%;%PYTHON_BIN%
CALL emsdk install latest
CALL emsdk activate latest
CALL emsdk_env.bat
CALL emsdkpy/emsdk install latest
CALL emsdkpy/emsdk activate latest
CALL emsdkpy/emsdk_env.bat
CALL python -c "import sys; print(sys.executable)"
CALL emcc.bat -v
8 changes: 4 additions & 4 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
emconfig = os.environ['EM_CONFIG']
upstream_emcc = os.path.join('upstream', 'emscripten', 'emcc')
fastcomp_emcc = os.path.join('fastcomp', 'emscripten', 'emcc')
emsdk = './emsdk'
emsdk = 'emsdkpy/emsdk'
if WINDOWS:
upstream_emcc += '.bat'
fastcomp_emcc += '.bat'
emsdk = 'emsdk.bat'
emsdk = 'emsdkpy/emsdk.bat'
else:
emsdk = './emsdk'
emsdk = 'emsdkpy/emsdk'

# Utilities

Expand Down Expand Up @@ -81,7 +81,7 @@ def hack_emsdk(marker, replacement):

# Set up

TAGS = json.loads(open('emscripten-releases-tags.json').read())
TAGS = json.loads(open('emsdkpy/emscripten-releases-tags.json').read())

# Tests

Expand Down
18 changes: 9 additions & 9 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ set -e

# Test that arbitrary (non-released) versions can be installed and
# activated.
./emsdk install sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
./emsdk activate sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
source ./emsdk_env.sh
emsdkpy/emsdk install sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
emsdkpy/emsdk activate sdk-upstream-5c776e6a91c0cb8edafca16a652ee1ee48f4f6d2
source emsdkpy/emsdk_env.sh
which emcc
emcc -v

# Install an older version of the SDK that requires EM_CACHE to be
# set in the environment, so that we can test it is later removed
./emsdk install sdk-fastcomp-3b8cff670e9233a6623563add831647e8689a86b
./emsdk activate sdk-fastcomp-3b8cff670e9233a6623563add831647e8689a86b
source ./emsdk_env.sh
emsdkpy/emsdk install sdk-fastcomp-3b8cff670e9233a6623563add831647e8689a86b
emsdkpy/emsdk activate sdk-fastcomp-3b8cff670e9233a6623563add831647e8689a86b
source emsdkpy/emsdk_env.sh
which emcc
emcc -v
test -n "$EM_CACHE"

# Install the latest version of the SDK which is the expected precondition
# of test.py.
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh --build=Release
emsdkpy/emsdk install latest
emsdkpy/emsdk activate latest
source emsdkpy/emsdk_env.sh --build=Release
# Test that EM_CACHE was unset
test -z "$EM_CACHE"

Expand Down
4 changes: 2 additions & 2 deletions test/test_activation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ $PATH_Process_BEFORE = [System.Environment]::GetEnvironmentVariable("PATH", "Pro

try {

& "$repo_root/emsdk.ps1" install latest
& "$repo_root/emsdkpy/emsdk.ps1" install latest

$esc = '--%'
& "$repo_root/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG
& "$repo_root/emsdkpy/emsdk.ps1" activate latest $esc $env:PERMANENT_FLAG $env:SYSTEM_FLAG

if ($env:SYSTEM_FLAG) {
$env_type = "Machine"
Expand Down
6 changes: 3 additions & 3 deletions test/test_bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ set -e

# Get the latest version number from emscripten-releases-tag.json.
VER=$(grep -oP '(?<=latest\": \")([\d\.]+)(?=\")' \
emscripten-releases-tags.json \
emsdkpy/emscripten-releases-tags.json \
| sed --expression "s/\./\\\./g")
# Based on the latest version number, get the commit hash for that version.
HASH=$(grep "\"${VER}\"" emscripten-releases-tags.json \
HASH=$(grep "\"${VER}\"" emsdkpy/emscripten-releases-tags.json \
| grep -v latest \
| cut -f4 -d\")

Expand All @@ -31,4 +31,4 @@ bazel build //:hello-embind-wasm --compilation_mode dbg # debug
# Test use of the closure compiler
bazel build //:hello-embind-wasm --compilation_mode opt # release
# This function should not be minified if the externs file is loaded correctly.
grep "customJSFunctionToTestClosure" bazel-bin/hello-embind-wasm/hello-embind.js
grep "customJSFunctionToTestClosure" bazel-bin/hello-embind-wasm/hello-embind.js
Loading